Class: request

request

Nodejs request object, extended not only by ExpressJS , but also by HuntJS. It have some additional objects in it

Constructor

new request()

Properties:
Name Type Description
user User | null

currently authenticated by means of http://passportjs.org

model model

shortcut to all Hunt models

redisClient Object

ready to use redis client

huntEmit function

use Hunt event emitter

io Object

Ready to use http://socket.io object with passport.js integration

preload Preload | null

result of usage of Hunt#preload middleware, containing the Hunt#model instance

files Object

result of usage of Hunt#multipart middleware, containing info about uploaded files

See:

Methods

flash()

connect-flash exposes a flash() function on request. The flash is a special area of the session used for storing messages. Messages are written to the flash and cleared after being displayed to the user. The flash is typically used in combination with redirects, ensuring that the message is available to the next page that is to be rendered.

Example
hunt.extendController(function(core, router){
  router.get('/flash', function(req, res){
    // Set a flash message by passing the key, followed by the value, to req.flash().
    req.flash('info', 'Flash is back!')
    res.redirect('/');
  });

  router.get('/', function(req, res){
    // Get an array of flash messages by passing the key to req.flash()
    res.render('index', { messages: req.flash('info') });
  });
});

logIn()

Passport.js exposes a login() function on request (also aliased as logIn()) that can be used to establish a login session.

Tutorials:
Example
req.login(user, function(err) {
  if (err) {
    throw err;
  }
  res.redirect('/users/' + req.user.username);
});

login()

Passport.js exposes a login() function on request (also aliased as logIn()) that can be used to establish a login session.

Tutorials:
Example
req.login(user, function(err) {
  if (err) {
    throw err;
  }
  res.redirect('/users/' + req.user.username);
});

logout()

Passport.js exposes a logout() function on request (also aliased as logOut()) that can be called from any route handler which needs to terminate a login session. Invoking logout() will remove the req.user property and clear the login session (if any).

Tutorials:
Example
hunt.extendController(function(core, router){
  router.get('/logout', function(req, res){
    req.logout();
    res.redirect('/');
  });
});

logOut()

Passport.js exposes a logout() function on request (also aliased as logOut()) that can be called from any route handler which needs to terminate a login session. Invoking logout() will remove the req.user property and clear the login session (if any).

Tutorials:
Example
hunt.extendController(function(core, router){
  router.get('/logout', function(req, res){
    req.logout();
    res.redirect('/');
  });
});