本文整理汇总了TypeScript中connect-redis类的典型用法代码示例。如果您正苦于以下问题:TypeScript connect-redis类的具体用法?TypeScript connect-redis怎么用?TypeScript connect-redis使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了connect-redis类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: connectRedis
/// <reference types="express-session" />
import * as connectRedis from "connect-redis";
import * as session from "express-session";
let RedisStore = connectRedis(session);
示例2: redisStore
import {SessionConfig, CacheConfig} from '../Config';
import {GetRouter, Router, AuthMiddleware } from './Core';
import * as passport from 'passport';
import * as session from 'express-session';
import * as redisStore from 'connect-redis';
import Auth from './Modules/AppManager/Router/Auth';
import AppManager from './Modules/AppManager/Router';
let Store = redisStore(session);
SessionConfig.store = new Store(CacheConfig);
var route: Router = GetRouter();
route.use(session(SessionConfig));
route.use(passport.initialize());
route.use(passport.session());
route.use('/Auth', Auth);
route.use(AuthMiddleware);
route.use('/AppManager', AppManager);
export = route;
示例3: async
const start = async() => {
const app = express()
/**
* 日志处理
*/
app.use(morgan('combined', {
stream: {
write: message => logger.error(message.trim())
},
skip: (req, res) => res.statusCode < 400
}))
/**
* session 中间件
*/
const RedisStore = connectRedis(expressSession)
app.use(expressSession({
secret: config.sessionSecret,
cookie: {
maxAge: config.sessionMaxAge
},
saveUninitialized: false,
resave: false,
store: new RedisStore({
host: config.redisHostName,
port: config.redisPort
})
}))
/**
* cookie 中间件
*/
app.use(cookieParser(config.sessionSecret))
/**
* 压缩资源
*/
app.use(compression())
/**
* 设置静态资源缓存
*/
// 编译后的静态文件路径
const builtStaticPath = process.env.NODE_ENV === 'production' ? 'built-production/static' : 'built/static'
app.use('/static', express.static(builtStaticPath))
/**
* 解析请求 body
*/
app.use('/api', bodyParser.json())
app.use('/api', bodyParser.urlencoded({extended: true}))
/**
* 接口
*/
// 等待数据库连接 ready
try {
await db
} catch (error) {
console.log('数据库连接失败', db)
}
app.use('/api', routes())
/**
* 默认输出页面模板
*/
app.get('*', (req, res) => {
res.set('Content-Type', 'text/html')
res.send(templateHtml)
})
/**
* 捕获应用抛出的错误
*/
interface Error {
status?: number
message?: string
}
app.use((error: Error, req: express.Request, res: express.Response, next: express.NextFunction) => {
res.status(error.status || 500).send({
message: error.message
})
logger.error('handledError', error, {requestParam: req.body})
})
/**
* 监听端口
*/
app.listen(config.localPort, () => {
// 开发模式弹窗,告知已重启 node 服务
if (process.env.NODE_ENV !== 'production') {
const notifier = require('node-notifier')
notifier.notify(`server start on port: ${config.localPort}`)
}
})
//.........这里部分代码省略.........