Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
kth-node-express-routing
Advanced tools
Readme
This is a wrapper for express route to allow generating named path files for app routes. It is used på KTH node-web projects to pass urls to browser clients.
PageRouter allows us to register page style routes that are registered in the path definition files.
Usage:
const AppRouter = require('kth-node-express-routing').PageRouter
const getPaths = require('kth-node-express-routing').getPaths
const server = require('express')()
const systemRoute = AppRouter()
systemRoute.get('system.monitor', '/_monitor', function (req, res) { ... })
server.use('/', systemRoute.getRouter())
const appRoute = AppRouter()
appRoute.get('app.index', '/', function (req, res) { ... })
server.use('/', appRoute.getRouter())
const paths = getPaths()
/*
paths = {
system: {
monitor: {
uri: '/_monitor',
method: 'get
}
},
app: {
index: {
uri: '/',
method: 'get
}
}
}
*/
ApiRouter allows us to register api endpoints by passing api endpoint definition objects from the paths file. It will set req.scope and add the authByApiKey middleware passed to ApiRouter IF the apiDefObj passed below evaluates apikey.scope_required == true
Usage in your node-api app:
// Middleware to protect enpoints with apiKey
const authByApiKey = passport.authenticate('apikey', { session: false })
const ApiRouter = require('kth-node-express-routing').ApiRouter
const apiRoute = ApiRouter(authByApiKey)
const apiDefObj = {
uri: "/api/node/data/:id/api/node/v1",
method: "GET",
apikey: {
scope_required: true,
scopes: ["read"],
type: "api_key"
}
}
// A middleware adding the access scope requriements (req.scope) and the authByApiKey is automatically
// prepended to the middleware pipeline
apiRoute.register(apiDefObj, function (req, res) { ... })
FAQs
Define named routes using express routing syntax. Allows exporting route defs javascript object
The npm package kth-node-express-routing receives a total of 1,171 weekly downloads. As such, kth-node-express-routing popularity was classified as popular.
We found that kth-node-express-routing demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers 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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.