Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eddywashere/middleware-responder
A node.js middleware for setting render and redirect options on the req object
https://github.com/eddywashere/middleware-responder
Last synced: 25 days ago
JSON representation
A node.js middleware for setting render and redirect options on the req object
- Host: GitHub
- URL: https://github.com/eddywashere/middleware-responder
- Owner: eddywashere
- Created: 2014-10-15T05:39:34.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-10-15T05:39:38.000Z (about 10 years ago)
- Last Synced: 2024-10-10T01:42:11.863Z (29 days ago)
- Language: JavaScript
- Size: 97.7 KB
- Stars: 6
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# middleware-responder
[![Build Status](https://travis-ci.org/eddywashere/middleware-responder.png?branch=master)](https://travis-ci.org/eddywashere/middleware-responder)
A node.js middleware for setting render and redirect options on the req object. Specifically `req.render` and `req.redirect`.
To install:
```
npm install middleware-responder --save
```Example usage:
routes.js
```js
var setRedirect = require('middleware-responder').setRedirect;
var setRender = require('middleware-responder').setRender;app.get('/',
setRender('home'), // req.render = 'homepage';
userController.home);app.post('/login',
setRedirect({failure: '/', success: '/dashboard'}), // req.redirect = {failure: '/', success: '/dashboard'};
userController.postLogin);
```user-controller.js
```js
exports.home = function(req, res, next){
// app logic hereres.render(req.render); // 'home'
};exports.postLogin = function(req, res, next){
// login logic here
if(req.user){
return res.redirect(req.redirect.success); // redirects to 'dashboard';
}res.redirect(req.redirect.failure); // redirect to '/'
};
```