本文整理汇总了TypeScript中koa-bodyparser类的典型用法代码示例。如果您正苦于以下问题:TypeScript koa-bodyparser类的具体用法?TypeScript koa-bodyparser怎么用?TypeScript koa-bodyparser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了koa-bodyparser类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: next
import * as jwt from 'jsonwebtoken';
import * as mount from 'koa-mount';
import * as responseTime from 'koa-response-time';
import { UserService } from './routes/users/user.service';
import { BindRoutes } from './routes';
const APP_CONFIG = config.get('app');
const JWT_CONFIG = config.get('jwt');
const app = new Koa();
const userService = new UserService();
// X-Response-Time
app.use(responseTime());
// Body Parsing
app.use(bodyparser());
// 404 Handler
app.use(async (ctx, next) => {
await next();
if (ctx.status === 404) {
ctx.response.status = 404;
ctx.response.body = {
error: true,
message: 'Entity not found'
};
}
});
// 401 Handler
app.use(async (ctx, next) => {
开发者ID:HackrLabs,项目名称:HakrPass,代码行数:31,代码来源:server.ts
示例2: next
rolling: false,
renew: false,
};
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
示例3: Koa
import * as serve from 'koa-static';
import * as cors from 'koa2-cors';
import * as path from 'path';
import rank from './routes/rank';
import news from './routes/news';
import analytics from './routes/analytics';
import summarize from './routes/summarize';
import { crawlJob } from './database/crawler';
const app = new Koa();
const port = process.env.PORT || 3000;
const dist = path.join(__dirname, '..', 'public');
const bpOption = { extendTypes: { json: ['application/x-javascript'] } };
app
.use(koaLogger())
.use(bodyParser(bpOption))
.use(cors())
.use(rank.routes())
.use(analytics.routes())
.use(news.routes())
.use(summarize.routes())
.use(serve(dist));
if (process.argv[2] === '--with-crawler') {
crawlJob.start();
}
app.listen(port, () => logger.info(`Listening on PORT ${port}`));
开发者ID:endlessdev,项目名称:PortalRank,代码行数:30,代码来源:app.ts
注:本文中的koa-bodyparser类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论