本文整理汇总了TypeScript中tyranid.Tyr.connect方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Tyr.connect方法的具体用法?TypeScript Tyr.connect怎么用?TypeScript Tyr.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tyranid.Tyr
的用法示例。
在下文中一共展示了Tyr.connect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: before
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 });
});
});
示例2: Promise
await new Promise((resolve, reject) => {
const http = app.listen(expressPort, () => {
// console.log('Express listening on port ' + expressPort)
resolve();
});
Tyr.connect({ http });
});