本文整理汇总了TypeScript中koa-session类的典型用法代码示例。如果您正苦于以下问题:TypeScript koa-session类的具体用法?TypeScript koa-session怎么用?TypeScript koa-session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了koa-session类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: require
import * as session from 'koa-session';
import * as Koa from 'koa';
import RedisStore = require('koa2-session-redis');
const app = new Koa();
const CONFIG = {
store: new RedisStore({
host: '127.0.0.1',
port: 6379,
max_attempts: 0
})
};
app.use(session(CONFIG, app));
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:15,代码来源:koa2-session-redis-tests.ts
示例2: Koa
import * as Koa from 'koa';
import * as session from 'koa-session';
import {ip, port} from '../config/server';
import renderApp from './render-app';
const app = new Koa();
app.use(session(app));
app.use(renderApp);
app.listen(port, () => {
// eslint-disable-next-line no-console
console.log(`[init] listening on ${ip}:${port}`);
});
export default app;
开发者ID:debchn,项目名称:shopify-app,代码行数:18,代码来源:index.ts
示例3: next
// const debug = true
import * as Koa from 'koa'
import * as session from 'koa-session'
import * as logger from 'koa-logger'
import * as serve from 'koa-static'
import * as body from 'koa-body'
import * as cors from 'kcors'
import router from '../routes'
import config from '../config'
const app = new Koa()
let appAny: any = app
appAny.counter = { users: {}, mock: 0 }
app.keys = config.keys
app.use(session(config.session, app))
if (process.env.NODE_ENV === 'development') app.use(logger())
app.use(async(ctx, next) => {
await next()
if (ctx.path === '/favicon.ico') return
ctx.session.views = (ctx.session.views || 0) + 1
let app: any = ctx.app
if (ctx.session.fullname) app.counter.users[ctx.session.fullname] = true
})
app.use(cors({
credentials: true
}))
app.use(async(ctx, next) => {
await next()
if (typeof ctx.body === 'object' && ctx.body.data !== undefined) {
ctx.type = 'json'
开发者ID:zerolugithub,项目名称:rap2-delos,代码行数:31,代码来源:app.ts
示例4: Koa
decode("123");
hash("abc");
const app = new Koa();
app.use(session({
valid: (ctx, sess) => {
const { session: s } = ctx;
if (s) {
s.sess = "validated";
s.save();
return true;
}
return false;
},
store: {
get: async (key) => {
return "abc";
},
set: (key, val) => {
console.log(key, val);
},
destroy: (key) => {
console.log(key);
},
},
}, app));
app.listen(3000);
开发者ID:DavidM77,项目名称:DefinitelyTyped,代码行数:30,代码来源:koa-session-tests.ts
示例5: next
};
app.keys = ["some secret hurr"];
// 错误处理
app.use(async (ctx, next) => {
try {
await next();
} catch (err) {
errorHandler(ctx, next, err);
}
});
app.use(bodyParse());
app.use(session(sessionConfig, app));
// app.use((ctx, next) => {
// const userName = ctx.session.user || "";
// });
app.use(apiRouters.routes()).use(apiRouters.allowedMethods());
app.use((ctx, next) => {
// 根据状态码抛出相应错误
const statusCode = ctx.response.status;
switch (statusCode) {
case 404:
throw new ResourceNotFoundError(ctx.request.method, ctx.request.url, "没有找到您所需要的资源");
}
});
开发者ID:IWSR,项目名称:Blog_system,代码行数:31,代码来源:index.ts
注:本文中的koa-session类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论