本文整理匯總了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 });
});