Refactor to prep for accessing cookie/session data from within socket.io connections.
This commit is contained in:
parent
7cff1443aa
commit
ef773b4a44
33
server.js
33
server.js
@ -1,12 +1,28 @@
|
|||||||
var express = require("express");
|
var express = require('express');
|
||||||
var bodyParser = require("body-parser");
|
|
||||||
var app = express();
|
var app = express();
|
||||||
|
var bodyParser = require('body-parser');
|
||||||
|
app.use(bodyParser.text()); // Use defaults for now, size limit is 100kb.
|
||||||
|
app.use(bodyParser.urlencoded({ extended: true })); // Also need url encoding to handle login form.
|
||||||
var winston = require('winston');
|
var winston = require('winston');
|
||||||
winston.add(winston.transports.File, { filename: './logs/notes.kaplon.us.log', maxsize: 5000000 }); // 5MB
|
winston.add(winston.transports.File, { filename: './logs/notes.kaplon.us.log', maxsize: 5000000 }); // 5MB
|
||||||
var fileSystem = require('fs');
|
var fileSystem = require('fs');
|
||||||
|
var notePath = __dirname + '/note-data/allNotes.txt';
|
||||||
|
var favicon = require('serve-favicon');
|
||||||
|
app.use(favicon(__dirname + '/assets/favicon.ico')); // Put this before setting static dir.
|
||||||
|
app.use(express.static('assets'));
|
||||||
|
|
||||||
|
/*-----------------------------------------
|
||||||
|
Ordering of these configs is important, don't shuffle them around.
|
||||||
|
------------------------------------------*/
|
||||||
var passport = require('passport');
|
var passport = require('passport');
|
||||||
var Strategy = require('passport-local').Strategy;
|
var Strategy = require('passport-local').Strategy;
|
||||||
var db = require('./db');
|
var db = require('./db');
|
||||||
|
var cookieParser = require('cookie-parser');
|
||||||
|
app.use(cookieParser());
|
||||||
|
var sessionStore = new require('express-session').MemoryStore();
|
||||||
|
var session = require('express-session')({ secret: 'here kitty kitty', resave: false, saveUninitialized: false, store: sessionStore });
|
||||||
|
app.use(session);
|
||||||
|
//----------------------------
|
||||||
|
|
||||||
// Configure the local strategy for use by Passport.
|
// Configure the local strategy for use by Passport.
|
||||||
// The local strategy require a `verify` function which receives the credentials
|
// The local strategy require a `verify` function which receives the credentials
|
||||||
@ -40,17 +56,6 @@ passport.deserializeUser(function(id, cb) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.set('views', __dirname + '/views');
|
|
||||||
var favicon = require('serve-favicon');
|
|
||||||
app.use(favicon(__dirname + '/assets/favicon.ico')); // Put this before setting static dir.
|
|
||||||
|
|
||||||
app.use(express.static('assets'));
|
|
||||||
app.use(require('cookie-parser')());
|
|
||||||
app.use(bodyParser.text()); // Use defaults for now, size limit is 100kb.
|
|
||||||
app.use(bodyParser.urlencoded({ extended: true })); // Also need url encoding to handle login form.
|
|
||||||
app.use(require('express-session')({ secret: 'here kitty kitty', resave: false, saveUninitialized: false }));
|
|
||||||
var notePath = __dirname + '/note-data/allNotes.txt';
|
|
||||||
|
|
||||||
// Initialize Passport and restore authentication state, if any, from the session.
|
// Initialize Passport and restore authentication state, if any, from the session.
|
||||||
app.use(passport.initialize());
|
app.use(passport.initialize());
|
||||||
app.use(passport.session());
|
app.use(passport.session());
|
||||||
@ -80,7 +85,7 @@ app.get('/login', function(req, res){
|
|||||||
app.post('/login',
|
app.post('/login',
|
||||||
passport.authenticate('local', { failureRedirect: '/login' }),
|
passport.authenticate('local', { failureRedirect: '/login' }),
|
||||||
function(req, res) {
|
function(req, res) {
|
||||||
winston.info('sucessful login');
|
winston.info('sucessful login for user, ' + req.user.username);
|
||||||
res.redirect('/');
|
res.redirect('/');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user