Skip to content

nkt/restify-state

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Restify state

Module provides middlewares for saving state between requests for restify.

Installation

npm install restify-state

Usage

const restify = require('restify');
const restifyState = require('restify-state');

let server = restify.createServer({
  name: 'app'
});

server.use(restifyState.cookieParser());
server.use(restifyState.session({ // default
  name: 'user_session',
  proxy: false,
  store: null,
  path: '/',
  domain: '',
  lifetime: 30 * 24 * 60 * 60,
  secure: false
}));


server.get('/counter', (req, res) => {
  if (req.session.counter) {
    req.session.counter++;
  } else {
    req.session.counter = 1;
  }

  res.send({
    counter: req.session.counter
  });
});

License

MIT