-
-
Save anonymous/ac774ab0f277f04f633864c85372ba1b to your computer and use it in GitHub Desktop.
express-session管理
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
import express = require('express'); | |
import session = require('express-session'); | |
import connectRedis = require('connect-redis'); | |
const app = express(); | |
var RedisStore = connectRedis(session); | |
class Main { | |
constructor() { | |
app.use( | |
session({ | |
secret : 'secret' | |
, resave : true | |
, saveUninitialized : true | |
, store : new RedisStore ({ | |
host : '127.0.0.1' | |
, port : 6379 | |
, prefix:'dev.blog' | |
}) | |
, cookie : { | |
path : '/' | |
} | |
}) | |
); | |
app.get('/', (req, res, next) => { | |
res.send(req.session); | |
}) | |
app.listen(8080); | |
} | |
} | |
let main = new Main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment