本文整理匯總了TypeScript中express-session.default方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript express-session.default方法的具體用法?TypeScript express-session.default怎麽用?TypeScript express-session.default使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express-session
的用法示例。
在下文中一共展示了express-session.default方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: server
export default function server(session: any): express.Express {
// Init server
const app: express.Express = express();
app.disable('x-powered-by');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser(config.cookiePass));
// Session settings
app.use(expressSession(session));
// CSRF
app.use(csrf({
cookie: false
}));
// CORS
app.use(cors({
origin: true,
credentials: true
}));
app.use((req, res, next) => {
res.header('X-Frame-Options', 'DENY');
next();
});
router(app);
return app;
}
示例2: function
export default function(cthulhu: Application, secret: string) {
if (secret === void 0) { throw Error("Must provide `secret` in configuration"); }
cthulhu.use(session({
genid(req) {
return uuid.v4();
},
// Do not save session if nothing has been modified
resave: false,
// Do not create session unless something is to be stored
saveUninitialized: false,
secret,
}));
}
示例3: default
export default (app: any) =>
{
app
.set('views', __dirname + '/../../views')
.set('view engine', 'jade')
app
.use(compress())
.use(express.static(__dirname + '/../../../public'))
.use(bodyParser.json())
.use(bodyParser.urlencoded({extended: true}))
.use(session({secret: 'keyboard cat', resave: true, saveUninitialized: true}))
.use(passport.initialize())
.use(passport.session())
.use(morgan('dev'))
}
示例4: function
db.once('open', function () {
console.log("Get passport...")
let passport = require("./passport");
console.log("Add middleware...");
let app = express();
if (process.env.NODE_ENV === 'production') {
require('express-http2-workaround')({ express: express, http2: http2, app: app });///Fix http2 and express compatibility.
}
let st = [__dirname, ...config.staticLocation]
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(...st)));
}
let sessionOpts = {
saveUninitialized: true, // saved new sessions
resave: false, // do not automatically write to the session store
store: new MongoStore({ mongooseConnection: mongoose.connection }),
secret: config.db.secret,
cookie: { httpOnly: true, maxAge: 2419200000 } // configure when sessions expires
}
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }))
app.use(cookieParser(config.db.secret))
app.use(flash())//This is how we setup flash fail authentication.
app.use(session(sessionOpts));
app.use(passport.initialize());///Attach passport to express middleware.
app.use(passport.session());
if (config.jsTogz) {
app.get('*.js', function (req, res, next) {
req.url = req.url + '.gz';
res.set('Content-Encoding', 'gzip');
next();
});
}
console.log("Add routes...");
require('./routes/index')(app, passport);
console.log("");
let options = {
key: fs.readFileSync(config.ssl.key),
cert: fs.readFileSync(config.ssl.cert)
};
if (process.env.NODE_ENV === 'production') {
http2.createServer(options, app).listen(config.port, (error) => {
if (error) {
console.error(error)
return process.exit(1)
} else {
console.log('Listening on port: ' + config.port + '.')
}
});
} else {
http.createServer(app).listen(config.port, (error) => {
if (error) {
console.error(error)
return process.exit(1)
} else {
console.log('Listening on port: ' + config.port + '.')
}
});
}
});
示例5: main
async function main() {
const app = express();
app.use(cors());
await initAccounts();
app.use(session({
secret: 'grant',
resave: true,
saveUninitialized: true,
}));
app.use(bodyParser.urlencoded({ extended: true }));
const grant = new Grant(grantConfig);
app.use(GRANT_PATH, grant);
app.get(`${GRANT_PATH}/handle_facebook_callback`, function (req, res) {
const accessToken = req.query.access_token;
res.redirect(`${STATIC_SERVER}/login?service=facebook&access_token=${accessToken}`);
});
app.get(`${GRANT_PATH}/handle_google_callback`, function (req, res) {
const accessToken = req.query.access_token;
res.redirect(`${STATIC_SERVER}/login?service=google&access_token=${accessToken}`);
});
initializeOAuthResolver();
const schema = createSchemeWithAccounts(AccountsServer);
app.use('/graphql', bodyParser.json(), graphqlExpress(request => ({
schema,
context: JSAccountsContext(request),
debug: true,
})));
app.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql',
}));
const server = createServer(app);
new SubscriptionServer(
{
schema,
execute,
subscribe,
},
{
path: WS_GQL_PATH,
server,
}
);
server.listen(PORT, () => {
console.log('Mock server running on: ' + PORT);
});
}
示例6: startServer
function startServer(callback) {
const fileStore = sessionFileStore(expressSession);
let app = express();
app.use(cookieParser());
app.use(bodyParser.urlencoded({extended: true}));
app.use(expressSession({
store: new fileStore(),
secret: 'alarm-clock',
resave: false,
saveUninitialized: true,
cookie: {
expires: new Date(253402300000000) // Approximately Fri, 31 Dec 9999 23:59:59 GMT
}
}));
app.use(passport.initialize());
routes(app);
app.use(express.static(path.join(__dirname, '../../web/static')));
app.use(express.static(path.join(__dirname, '../../build-web')));
app.use(function (req: express.Request, res: express.Response, next: express.NextFunction) {
console.log('Invalid path: ' + req.originalUrl);
next();
});
app.listen(PORT, callback)
}
示例7: start
start() {
let app: express.Express = express();
app.use('/', express.static('public'));
var upload: multer.Instance = multer(); // for parsing multipart/form-data
//Server Middlewares configuration part
app.use(allowCrossDomain);
app.use(cookieParser()); // read cookies (needed for auth)
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.use(expressSession({secret: 'swcmi'}));
//To use passport
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
//start router
this.apiRouter.init(app);
//port
app.listen(10000, function () {
console.log('SuWon church API Server listening on port 10000!')
});
}
示例8: bootstrap
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.use(
session({
secret:'No sera de tomar un traguito',
resave: false,
saveUninitialized: true,
cookie: {secure: false},
name: 'server-session-id',
store: new FileStore()
})
);
app.use(cookieParser(
'me gustan los tacos', // secreto
{ // opciones
}
));
app.set('view engine', 'ejs');
app.use(
express.static('publico')
);
await app.listen(3000);
}
示例9: next
before(async () => {
Location = Tyr.byName.location;
User = Tyr.byName.user;
Subscription = Tyr.byName.tyrSubscription;
Job = Tyr.byName.job;
app = express();
const MongoStore = connectMongo(session);
const store = new MongoStore({
url: 'mongodb://localhost:27017/tyranid_test',
stringify: false
});
const COOKIE_SECRET = 'tyranid-test-secret';
const sessionHandler = session({
secret: COOKIE_SECRET,
resave: false,
rolling: true,
saveUninitialized: true,
store
});
Tyr.connect({ store });
const user = await User.byId(1);
app.use((req, res, next) => sessionHandler(req, res, next));
app.use((req, res, next) => {
if (req.session) {
req.session.passport = { user: user!._id }; // "log in" user 1
}
return next();
});
app.use(bodyParser.json());
Tyr.connect({
app,
auth: (req, res, next) => {
(req as any).user = user; // "log in" user 1
return next();
}
});
await new Promise((resolve, reject) => {
const http = app.listen(expressPort, () => {
// console.log('Express listening on port ' + expressPort)
resolve();
});
Tyr.connect({ http });
});
});
示例10: setup
public setup() {
this.logger.debug("Enabling session....");
this.app.use(expressSession({
cookie: { maxAge: 3600000 * 12 },
resave: false,
saveUninitialized: true,
secret: credentials.Session.secretPhrase,
unset: "destroy",
}));
this.logger.debug("Session configured.");
}