npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

magnolia-mock-server

v0.2.0

Published

This CLI tool allows you to quickly provide a copy of your CMS website content via a Magnolia-like API.

Downloads

6

Readme

Magnolia Mock Server

This CLI tool allows you to quickly provide a copy of your CMS website content via a Magnolia-like API.

npx magnolia-mock-server ./content
# Server running at http://localhost:5000


About

Running Magnolia can be painful for front-end developers. It requires setting up infrastructure and tools we are not always familiar with so when they go wrong - which they do - that can leave people stuck and frustrated. And things are not always easy even when the CMS is up and running because Magnolia consumes a very large amount of resources which are vastly disproportionate to the requirements that front-end developers have; fetching a few hundred kilobytes of data.

For this reason many devs will configure their apps to fetch data from a remote instance of Magnolia instead of a local one but this can also lead to problems because - as a CMS - the content is always changing!

This small tool allows you to quickly serve a static copy of your JCR website content via a Magnolia-like API so you don't need to run Magnolia or depend upon a moving target.

Installation

This is a Node.js module available through the npm registry. Node 14 or above is required.

Installation is done using the npm install command:

$ npm install -D magnolia-mock-server

Usage

Command line

You can use the tool to serve a directory of YAML files containing your content using npx (which is installed with npm):

npx magnolia-mock-server --port 5000 ./content

Once running you can access the API via one of its endpoints.

Node.js

You can also use the tool programmatically by importing it into your JavaScript code:

const bootstrap = require("magnolia-mock-server");

try {
  await bootstrap(options);
} catch (err) {
  console.error(err);
}

Options

When using this tool via the CLI or in your Node.js modules it can be configured with a number of options. Most of the avilable options are analogous to Magnolia's delivery API configuration.

| Option | Type | Description | |----------------|----------|------------------------------------------------------------------| | port | number | Port number to run the mock server on. (default: 5000) | | sourceDir | string | Path to the directory containing your YAML files. | | rootPath | string | The root path of this endpoint. (default: "pages") | | depth | number | Specifies how deep the node tree will be traversed. (default: 0) | | nodeTypes | string[] | A comma-separated list of allowed node types for depth-0 nodes. | | childNodeTypes | string[] | A comma-separated list of allowed node types for child nodes. |

Endpoints

  • Query nodes: http://localhost:5000/.rest/delivery/pages/ (not implemented)
  • Read node: http://localhost:5000/.rest/delivery/pages/{path}
  • Get children: http://localhost:5000/.rest/delivery/pages/{path}/@nodes

Project setup

  1. Clone the Git repository and change to the new directory that has been created:

    git clone [email protected]:i-like-robots/magnolia-mock-server
    cd magnolia-mock-server
  2. Install all of the project dependencies using npm:

    npm install
  3. Copy your website data files (usually named website.{namespace}.yaml) into the content/ folder:

    cp ../magnolia-cms/website.example-site.yaml content/
  4. You can now start and visit the running application:

    npm start

    Then open http://localhost:5000/.rest/delivery/pages/ in your browser.

Troubleshooting

Why can't I access the query endpoint?

This is not currently implemented, you can only fetch nodes and children of nodes.

Does this app support JCR data saved as XML?

No, the app only supports JCR data saved in YAML format.

Can I configure the node depth and node types to return?

Yes, like the Magnolia delivery endpoint configuration you can filter my node type and tree depth.