http-plus-router
v0.0.3
Published
simple router for your core http module
Downloads
2
Readme
Simple router using http core, it's very light and you can modify its style with middleware style like express js.
example
For example, you can write the code below
'use strict';
const port = 3000;
const http = require('http');
const Router = require('http-plus-router');
Router.notfound({
type : {'Content-Type' : 'application/json'},
body : JSON.stringify({
status : 404,
message : 'route not found'
}, null, 3)
});
Router.find('/', (req, res) => {
res.writeHead(200, {'Content-Type' : 'text/html'});
res.end('Root page.');
});
Router.find('/about', (req, res) => {
res.writeHead(200, {'Content-Type' : 'text/html'});
res.end('About page.');
});
const app = http.createServer((req, res) => {
let handler = Router.register(req);
handler.execute(req, res);
});
app.listen(port, () => {
console.log(`Server Up On Port => ${port}.`);
});