ozylog-express
v0.2.1
Published
Express++
Downloads
5
Readme
ozylog-express
Express++
Description
Pretty much https://expressjs.com with some additional features
Usage
Router
new Router({pre: preMiddleware, post: postMiddleware}) // pre and post are optional
Example
import {Router} from 'ozylog-express';
const router = new Router({pre: preMiddleware, post: postMiddleware});
router.route('/').get(middleware1, middleware2);
// Access this route will execute these middlewares in order [preMiddleware, middleware1, middleware2, postMiddleware]
Request
req.resetState(), req.setState(object), req.combineState(object)
Example
import express from 'ozylog-express';
const app = express();
app.use((req, res, next) => {
req.resetState(); // req.state = {};
req.setState({hello: 'world'}); // req.state = {hello: 'world'};
req.setState({express: {
node: 'js'
}});
/*
req.state = {
hello: 'world',
express: {
node: 'js'
}
};
*/
req.combineState({express: {
is: 'awesome'
}});
/*
req.state = {
hello: 'world',
express: {
node: 'js',
is: 'awesome'
}
};
*/
req.setState({express: {
override: 'yes'
}});
/*
req.state = {
hello: 'world',
express: {
override: 'yes'
}
};
*/
});
Response
res.out(object)
Example
import express from 'ozylog-express';
const app = express();
app.use((req, res, next) => {
res.out({hello: 'world'}); // res.result = {hello: 'world'}
});
License
MIT