Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
@everestate/serverless-router
Advanced tools
Fast, minimalist, pluggable, universal router.
npm install @everestate/serverless-router --save
To use serverless-router
you will need at least one of its plugins.
const ServerlessRouter = require('@everestate/serverless-router');
const ServerlessRouterWebPlugin = require('@everestate/serverless-router-plugin-web');
cosnt userService = require('../services/userService');
function dispatch(event) {
const router = new ServerlessRouter([ServerlessRouterWebPlugin]);
router.web
.get('/users/:id', () =>
userService.getUserById(event.pathParameters.id)) // returns promise
.delete('/users/:id', () =>
userService.deleteUserById(event.pathParameters.id)); // returns promise
router.mismatch(() => {
const { path, httpMethod } = event;
return Promise.reject(new Error(`Unknown route: ${httpMethod} ${path}`));
});
return router.dispatch(event);
}
function myLambdaHandler(event, context, callback) {
return dispatch(event)
.then(result =>
callback(null, { statusCode: result.code, body: JSON.stringify({ payload: result.payload }) }))
.catch(error =>
callback(null, { statusCode: '500', body: JSON.stringify({ message: error.message }) }));
}
By default serverless-router
will throw error
on route mismatch.
It's possible to define custom mismatch handler, and it would be called with same arguments dispatch
was called:
router.mismatch((event, context, callback) => {
const { path, httpMethod } = event;
return callback(null, {
statusCode: '404',
body: JSON.stringify({ message: `ServerlessRouter can't find the route ${httpMethod} ${path}` }),
});
});
There are few implementations for testing purposes you might be interesting in:
lib/__tests__/__fixtures__/EvenOddPlugin.js
lib/__tests__/__fixtures__/TypePlugin.js
lib/__tests__/__fixtures__/WeekdayPlugin.js
@TODO: describe plugin implementation principles
FAQs
Serverless, minimalist, pluggable, universal router.
We found that @everestate/serverless-router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.