本文整理汇总了TypeScript中express-session.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: express
.then(() => {
const app = express();
const port = process.env.PORT || 3000;
// using default memory store so will be wiped sam way as the db
app.use(session({
secret: 'super secret',
resave: false, // can be false for redis not sure about memoryStore
saveUninitialized: false,
}));
// TODO: PERF: first response is pretty slow because it has to bundle all the things
// TODO: use tsify to generate correct source maps
app.get('/static/js/bundle.js', browserify(__dirname + '/../app/main.js', {}));
// register api routes
app.use('/api/v1/', api);
// serve files from the root so no security here, but some stuff is linked directly from node_modules
app.use('/', express.static(path.join(__dirname, '../'), { maxAge: 31557600000 }));
// catch all so we serve index on /stats
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '../index.html'));
});
app.listen(
port,
function() {
console.log('Express server listening on port %d', port);
}
);
})
示例2: session
export const getDefaultSettings = (app: Application, other?: Partial<OauthSetupSettings>) => {
const defaults: OauthSetupSettings = {
authService: app.get('defaultAuthentication'),
linkStrategy: 'jwt',
expressSession: session({
secret: Math.random().toString(36).substring(7),
saveUninitialized: true,
resave: true
}),
...other
};
return defaults;
};
示例3: require
/**
* This method let you configure the middleware required by your application to works.
* @returns {Server}
*/
public $onMountingMiddlewares(): void {
const cookieParser = require("cookie-parser"),
bodyParser = require("body-parser"),
compress = require("compression"),
methodOverride = require("method-override"),
expressSession = require("express-session");
this.use(TestAcceptMimeMiddleware)
.use(bodyParser.json())
.use(
bodyParser.urlencoded({
extended: true
})
)
.use(cookieParser())
.use(compress({}))
.use(methodOverride());
this.engine(".html", require("ejs").__express)
.set("views", `${rootDir}/views`)
.set("view engine", "html");
this.set("trust proxy", 1);
this.use(
expressSession({
secret: "keyboard cat",
resave: false,
saveUninitialized: true,
cookie: {}
})
);
this.use(InitSessionMiddleware);
}
示例4:
$onMountingMiddlewares(): void | Promise<any> {
this
.use(GlobalAcceptMimesMiddleware)
.use(cookieParser())
.use(compress({}))
.use(methodOverride())
.use(bodyParser.json())
.use(bodyParser.urlencoded({
extended: true
}))
.use(session({
secret: "mysecretkey",
resave: true,
saveUninitialized: true,
maxAge: 36000,
cookie: {
path: "/",
httpOnly: true,
secure: false,
maxAge: null
}
}));
return null;
}
示例5: setupSession
function setupSession(app: express.Express, config: IExpressConfig) {
// tslint:disable-next-line: variable-name
const RedisStore = connectRedis(expressSession);
const redis_client = redis.createClient(config.redis_port || 6379, config.redis_host || '127.0.0.1');
const session_store = new RedisStore({
client: redis_client,
pass: config.redis_password,
ttl: config.session_ttl,
});
session_store.on('disconnect', () => {
console.log('RedisStore for express is disconnected. Exit the process...');
setTimeout(() => {
process.exit(0);
}, 1000);
});
app.use(expressSession({
cookie: {
domain: config.session_domain,
maxAge: config.session_ttl * 1000,
},
name: config.session_name,
resave: true, // session expire를 초기로 돌리기 위해서 매번 다시 저장한다
saveUninitialized: config.session_save_uninitialized || false,
secret: config.session_secret,
store: session_store,
}));
}
示例6: function
module.exports = function (app) {
app.use(session({
secret: '123456789',
resave: false,
saveUninitialized: true
}));
app.post('/admin/login', function (req, res) {
admin.isAdmin(req.body.username, req.body.password).then(function (result) {
var loginResult:Object;
if (result.success) {
req.session.hash = (!_.isUndefined(result.isSuperAdmin)) ? 'superAdmin' : result.hash;
loginResult = { success: true, sessionId: req.sessionID };
} else {
req.session.destroy();
loginResult = { success: false };
}
res.json(loginResult);
});
});
app.get('/admin/checkAdminIsLogin', function (req, res) {
var loginResult = (!_.isUndefined(req.query.sessionId) && req.query.sessionId == req.sessionID);
res.json({ success: loginResult });
});
app.get('/admin/checkIsSuperAdmin', function (req, res) {
res.json({
success: !_.isUndefined(req.query.sessionId)
&& req.query.sessionId == req.sessionID
&& req.session.hash == 'superAdmin'
});
});
};
示例7: function
module.exports = function(app) {
var env = config.env;
app.set('view engine', 'html');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(compression());
app.use(morgan('dev'));
app.use(passport.initialize());
app.use(express.static(path.join(config.root, 'client')));
app.set('appPath', 'client');
app.use(session({
secret: config.secrets.session,
resave: true,
saveUninitialized: true,
store: new mongoStore({ mongooseConnection: mongoose.connection })
}));
if (env === 'development' || env === 'test') {
app.use(require('errorhandler')());
}
};
示例8: constructor
constructor() {
var express = require('express'),
logger = require('morgan'),
session = require('express-session')
var Grant = require('grant-express'),
grant = new Grant(require('./server/OAuthConfigure.json'))
var app = express()
app.use(logger('dev'))
// REQUIRED:
app.use(session({
secret: 'very secret'
}))
// mount grant
app.use(grant)
app.get('/handle_visualstudio_callback', function(req, res) {
console.log(req.query)
res.end(JSON.stringify(req.query, null, 2))
});
this.setupHttpServer(app);
}
示例9: ConnectMongo
export const enableSessions = (app: any, io: SocketIO.Server) => {
const MongoStore = ConnectMongo(expressSession);
const s = expressSession({
store: new MongoStore({ mongooseConnection: MongooseClient.getConnection() }),
secret: MajavashakkiSessionSecret,
resave: false,
saveUninitialized: true,
});
app.use(s);
io.use(socketIoSession(s, {autoSave: true}));
};
示例10: getSession
public getSession(mongooseConnection, mongoStore) {
return expressSession({
cookie: {
maxAge: 20 * 365 * 24 * 60 * 60 * 1000
},
resave: false,
saveUninitialized: true,
secret: process.env.SESSION_SECRET,
store: new mongoStore({
collection : 'loginSession',
mongooseConnection: mongooseConnection,
}),
});
}