Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@priestine/routing
Advanced tools
npm i --save @priestine/routing
or
yarn add @priestine/routing
import { withHttpRouter, HttpRouter } from '@priestine/routing';
import { createServer } from 'http';
/**
* Create an empty router
*/
const router = HttpRouter.empty();
/**
* Define a set of functions
*/
// Curried for creating header builders
// `ctx` has { request: IncomingMessage, response: ServerResponse, intermediate: {/* Your data */}, error? }
const setHeader = (name) => (value) => (ctx) => {
ctx.response.setHeader(name, value);
};
// Specifically, a Content-Type header builder (we could make it in one go tho)
const setContentTypeHeader = setHeader('Content-Type');
// Anything to be passed to the next middleware should be put to ctx.intermediate to keep request and response Node.js-ly pure
const buildHello = (ctx) => {
ctx.intermediate.helloWorld = {
id: 'hello-world',
message: 'Hello World!',
}
};
// You don't need to actually return the ctx. It's done for you automatically
// In case you run async code, you must create and return a Promise that will resolve when necessary
const sayHello = (ctx) => ctx.response.end(JSON.stringify(ctx.intermediate.helloWorld));
/**
* Register them in the router
*/
router
.get('/', [
setContentTypeHeader('application/json'),
buildHello,
sayHello,
])
.get(/^\/(\d+)\/?$/, [
setContentTypeHeader('text/html'),
buildHello,
sayHello,
])
;
/**
* Assign the router to serve Node.js HTTP server.
*/
createServer(withHttpRouter(router)).listen(3000);
// Go get http://localhost:3000
FAQs
Simple, declarative and dependency-free routing for Node.js
We found that @priestine/routing 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.