//npm modules
const express = require('express');
const uuid = require('uuid/v4')
const session = require('express-session')
const FileStore = require('session-file-store')(session);
// create the server
const app = express();
// add & configure middleware
app.use(session({
genid: (req) => {
console.log('Inside the session middleware')
console.log(req.sessionID)
return uuid() // use UUIDs for session IDs
},
store: new FileStore(),
secret: 'keyboard cat',
resave: false,
saveUninitialized: true
}))
// create the homepage route at '/'
app.get('/', (req, res) => {
console.log('Inside the homepage callback function')
console.log(req.sessionID)
res.send(`You got home page!\n`)
})
// create the login get and post routes
app.get('/login', (req, res) => {
console.log('Inside GET /login callback function')
console.log(req.sessionID)
res.send(`You got the login page!\n`)
})
app.post('/login', (req, res) => {
console.log('Inside POST /login callback function')
console.log(req.body)
res.send(`You posted to the login page!\n`)
})
// tell the server what port to listen on
app.listen(3000, () => {
console.log('Listening on localhost:3000')
})
Created
October 30, 2017 03:27
-
-
Save evangow/d8ac6942bb823cc7646e9761962d266f to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment