本文整理匯總了TypeScript中connect-redis.default方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript connect-redis.default方法的具體用法?TypeScript connect-redis.default怎麽用?TypeScript connect-redis.default使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類connect-redis
的用法示例。
在下文中一共展示了connect-redis.default方法的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}`)
}
})
//.........這裏部分代碼省略.........