當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript koa-bodyparser類代碼示例

本文整理匯總了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;未經允許,請勿轉載。