How to use the express.cookieParser function in express

To help you get started, we’ve selected a few express examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nswbmw / N-chat / app.js View on Github external
var express = require('express')
  , routes = require('./routes')
  , user = require('./routes/user')
  , http = require('http')
  , path = require('path');

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

var users = {};//存储在线用户列表的对象

app.get('/', function (req, res) {
  if (req.cookies.user == null) {
    res.redirect('/signin');
  } else {
    res.sendfile('views/index.html');
github SFDevLabs / backbone-bulletin-board / app.js View on Github external
app.configure(function () {
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.favicon(__dirname + '/public/favicon.ico'));
  app.use(express.logger('dev'));
  app.use(require('stylus').middleware({ src: __dirname + '/public' }));
  app.use(express.static(__dirname + '/public'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());


    // cookieParser should be above session

  app.use(express.cookieParser("thissecretrocks"))

  // express/mongo session storage
  app.use(express.session({
    secret: "thissecretrocks",
    store: new mongoStore({
      url: config.db,
      collection : 'sessions'
    })
  }))
});
app.use(flash())
github panbhag / easybackend / config / environments / all.js View on Github external
// Register formats for content negotiation.  Using content negotiation,
  // different formats can be served as needed by different clients.  For
  // example, a browser is sent an HTML response, while an API client is sent a
  // JSON or XML response.
  /* this.format('xml', { engine: 'xmlb' }); */

  // Use middleware.  Standard [Connect](http://www.senchalabs.org/connect/)
  // middleware is built-in, with additional [third-party](https://github.com/senchalabs/connect/wiki)
  // middleware available as separate modules.
  this.use(poweredBy('Locomotive'));
  this.use(express.logger());
  this.use(express.favicon());
  this.use(express.static(__dirname + '/../../public'));

  this.use(express.cookieParser());
 
  
  //converts to json if text, for the body parser
  this.use(function(req,res,next){
	
	if(req.is('text/*') )
	{
		req.headers['content-type'] = 'application/json; charset=UTF-8'
	}  
	next();
  })


  this.use(express.bodyParser());
github kevbook / Base-Node.js-App / loader / middleware.js View on Github external
module.exports = function(app, appRoot){

	var express = require('express'),
			errorHandler = require(appRoot + '/routes/errors')(app);

	// middleware (order sensitive)
	app.use(express.bodyParser());
	app.use(express.methodOverride());
	app.use(express.cookieParser('secretcode'));
	app.use(express.session({ secret: 'secretcode' }));
	app.use(express.csrf());

	app.configure('development', function(){
		// use AWS S3 to serve content in production
		app.use(express.static(appRoot + '/public'));
	});

	app.use(app.router);
	app.use(errorHandler.notFound); // 404 handler
	app.use(errorHandler.serverError); // 500 handler


	//helpers
	app.dynamicHelpers({
	  token: function(req, res) {
github jaredhanson / passport-hotp / examples / two-factor / server.js View on Github external
app.configure(function() {
  app.set('views', __dirname + '/views');
  app.set('view engine', 'ejs');
  app.engine('ejs', require('ejs-locals'));
  app.use(express.static(__dirname + '/../../public'));
  app.use(express.logger());
  app.use(express.cookieParser());
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.session({ secret: 'keyboard cat' }));
  app.use(flash());
  // Initialize Passport!  Also use passport.session() middleware, to support
  // persistent login sessions (recommended).
  app.use(passport.initialize());
  app.use(passport.session());
  app.use(app.router);
});
github enjalot / tributary / server.js View on Github external
//collection where we store info on inlets that are created and saved
var $inlets = db.collection("inlets");
//collection where we store visits (specifically to particular inlets)
var $visits = db.collection("visits");

//collection where we store images uploaded for thumbnails
var $images = db.collection("images");

//collection to store a cache of gists (for faster loading)
var cache = require('./cache');
var $gistcache = db.collection("gists");
$gistcache.ensureIndex({gistid:1}, false, function(err) { console.log(err) });

var app = express()
  .use(express.compress())
  .use(express.cookieParser())
  .use(express.bodyParser())
  .use(express.session({
    secret: settings.SECRET,
    cookie: {maxAge: ONE_YEAR},
    store: new MongoStore(mongoConf)
  }))
  .use('/static', express.static(__dirname + '/static'))

app.use(express.vhost('sandbox.' + settings.hostname || "localhost", require(__dirname + '/sandbox').app))


app.get("/", index);
function index(req, res, next) {
  res.sendfile(__dirname + '/templates/index.html');
};
github Thuzi / facebook-node-sdk / samples / scrumptious / app.js View on Github external
app.configure(function() {
    app.set('port', process.env.PORT || 3000);
    app.set('views', __dirname + '/views');
    app.set('view engine', 'ejs');
    app.use(express.favicon());
    app.use(express.logger('dev'));
    app.use(express.cookieParser());
    app.use(express.cookieSession({ secret: 'secret'}));
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(app.router);
    app.use(express.static(path.join(__dirname, 'public')));
});
github cconstantine / syslog-node / server.js View on Github external
app.configure(function () {
        app.use(express.static(__dirname + '/public'));
        app.use(express.cookieParser());
        app.use(express.bodyParser());
        app.use(express.session({
              store: sessionStore,
                secret: 'secret', key: 'express.sid'
                }));
        app.use(app.router);
      }); 
    sio = io.listen(app);
github island205 / technode-tutorial / how-to-build-chat-app-with-socket.io-and-angular / examples / chapter04 / TechNode / app.js View on Github external
var parseSignedCookie = require('connect').utils.parseSignedCookie
var Cookie = require('cookie')

var config = require('./config')
var api = require('./services/api')
var socketApi = require('./services/socketApi')

var port = process.env.PORT || 3000
var sessionStore = new MongoStore({
  url: config.mongodb
})

var app = express()

app.use(express.bodyParser())
app.use(express.cookieParser())
app.use(express.session({
  secret: 'technode',
  cookie: {
    maxAge: 60 * 1000 * 60
  },
  store: sessionStore
}))
app.use(express.static(__dirname + '/static'))

app.post('/api/login', api.login)
app.get('/api/logout', api.logout)
app.get('/api/validate', api.validate)

app.use(function(req, res) {
  res.sendfile('./static/index.html')
})
github scrollback / scrollback / http / express.js View on Github external
}

		next();
	});

	app.use(express.logger("AA/HTTP - [:date] :method :url :referrer :user-agent :status"));
	app.use(express.compress());
	app.use(express.static(__dirname + "/../" + config.home, {
		maxAge: 86400000
	}));

	if (process.env.NODE_ENV !== "production") {
		app.use(express.static(__dirname + '/../test/public'));
	}

	app.use(express.cookieParser());
	app.use(express.query());
	app.use(express.bodyParser());

	srv = http.createServer(app);

	srv.listen(config.port);
	app.httpServer = srv;

	if (config.https) {
		srvs = https.createServer({
			key: fs.readFileSync(__dirname + "/../" + config.https.key),
			cert: fs.readFileSync(__dirname + "/../" + config.https.cert),
			ca: !config.https.ca || fs.readFileSync(__dirname + "/../" + config.https.ca)
		}, app);
		srvs.listen(config.https.port);
		app.httpsServer = srvs;