Last active
September 10, 2016 14:56
-
-
Save ChALkeR/983e6a8a88b7e38f9febc52939b9e0ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var session = require('express-session'); | |
var FileStore = require('session-file-store')(session); | |
var store = new FileStore(); | |
var fake = { | |
set: (...args) => setTimeout(() => store.set(...args), 1000), | |
get: (...args) => store.get(...args), | |
createSession: (...args) => store.createSession(...args), | |
touch: (...args) => store.touch(...args), | |
destroy: (...args) => store.destroy(...args), | |
length: (...args) => store.length(...args), | |
list: (...args) => store.list(...args), | |
expired: (...args) => store.expired(...args), | |
on: (...args) => store.on(...args) | |
}; | |
var app = express(); | |
app.use(session({ | |
store: fake, | |
secret: 'secrets', | |
saveUninitialized: false, | |
resave: false | |
})); | |
app.get('/', (req, res) => { | |
res.send('counter: ' + req.session.bla + '<br/><a href="/increment">increment counter</a>') | |
}); | |
app.get('/increment', (req, res) => { | |
req.session.bla = 1 + (req.session.bla || 0); | |
res.redirect('/'); | |
}); | |
app.listen(3000, () => { | |
console.log('Listening on port 3000'); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment