
Security News
rv Is a New Rust-Powered Ruby Version Manager Inspired by Python's uv
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
express-json-middleware
Advanced tools
A simple minded way to pull in middleware based on a json config file.
A simple minded way to pull in middleware based on a json config file.
This npm is very minimal. Currently its feature list is exactly what I need. If you need other types of routes supports, pull requests / issues are welcome.
Create a routes.json file (or just an in memory array), and pass it in along with the express, express app, and the path to your middlewares directory:
var express = require('express'),
app = express(),
createRoutes = require('express-json-middleware'),
routes = require('./routes.json'),
path = require('path');
app.set('views' , __dirname + '/views');
app.set('view engine' , 'jade');
createRoutes({
app : app,
express : express,
routes : routes,
middlewares : path.join(__dirname, 'middlewares')
});
app.listen(process.env.PORT);
Your routes array or routes.json should be an array of arrays. Each line has 3 items.
use
command or an express supported verb.
use
the middleware on the appnull
if it should be set directly on the default router with no routes.Additionally you can create named stacks of middleware using the "stack" word for the first item, a name for the second item, and a list of middlewares for the thired. These have to be included before being applied. You can include the named stack in your later lists of middlewares and it will be expanded to the full list. This is handy if you have long lists of repeated middlewares.
[
[ "stack", "addPageParts", ["addHeader", "addFotter"]],
[ "GET", "/", ["addPageParts"]]
]
[
[ "use", "/", ["static"]],
[ "use", "/api/v1", ["grasshopper"]],
[ "GET", "/admin*?", ["admin"]],
[ "GET", "/:category/:subcategory/:product", ["page/product", "notFound"]],
[ "GET", "/:category/:subcategory", ["page/subcategory", "notFound"]],
[ "GET", "/:category", ["page/category", "notFound"]],
[ "GET", "*", ["notFound"]]
]
FAQs
A simple minded way to pull in middleware based on a json config file.
The npm package express-json-middleware receives a total of 0 weekly downloads. As such, express-json-middleware popularity was classified as not popular.
We found that express-json-middleware demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.