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


TypeScript koa-bodyparser.default函數代碼示例

本文整理匯總了TypeScript中koa-bodyparser.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了default函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: default

export default (app?: Koa) => {
  const provided = !!app

  const middlewares = [bodyParser(), router.routes(), router.allowedMethods()]

  if (!app) {
    app = new Koa()
    app.keys = app.keys = (process.env.APP_KEYS || '').split(',')
    middlewares.unshift(session({}, app))
  }

  if (provided) {
    return middlewares
  }

  app.use(compose(middlewares))

  app.listen(serverPort + 1, serverHost, () => {
    debug('Router server is now running at %s:%s', serverHost, serverPort + 1)
  })
}
開發者ID:JounQin,項目名稱:blog,代碼行數:21,代碼來源:index.ts

示例2: Application

	constructor() {
		this.app = new Application();
		this.app.use(koaLogger());
		this.app.use(koaResponseTime());
		this.app.use(koaBodyParser({ onerror: handleParseError }));
		this.app.use(koaErrorHandler());
		this.app.use(koaRestHandler());
		this.app.use(koaAuth());
		this.app.use(koaCors({ exposeHeaders, allowHeaders, origin, maxAge: 600, credentials: true, keepHeadersOnError: true }));
		this.app.use(koaJson({ pretty: false, param: 'pretty' }));
		this.app.use(apiCache.middleware.bind(apiCache));

		/* istanbul ignore next: host website at the same time, currently used for website CI */
		if (process.env.WEBAPP) {
			const webappPath = resolve(__dirname, process.env.WEBAPP);
			if (existsSync(webappPath)) {
				logger.warn(null, '[Server] Statically hosting website at %s', webappPath);
				this.app.use(koaWebsiteHandler(webappPath));
			} else {
				logger.warn(null, '[Server] Fix env WEBAPP, nothing found at %s (%s)', webappPath, process.env.WEBAPP);
			}
		}

		/* istanbul ignore if */
		if (process.env.ELASTIC_APM_ENABLED) {
			logger.info(null, '[Server] Elastic application performance monitoring at %s enabled.', process.env.ELASTIC_APM_SERVER_URL);
			this.setupApmFilter();
		}
	}
開發者ID:freezy,項目名稱:node-vpdb,代碼行數:29,代碼來源:server.ts

示例3: init

  static init(application, router) {
    let _root = process.cwd();
    let _nodeModules = "/node_modules";
    let _jspmPackages = "/jspm_packages";
    let _clientFiles = (process.env.NODE_ENV === "production") ? "/client/dist" : "/client/dev";

    application.use(bodyParser());
    application.use(router.routes());
    application.use(serve(_root + _nodeModules));
    application.use(serve(_root + _jspmPackages));
    application.use(serve(_root + _clientFiles));
  }
開發者ID:bernardbr,項目名稱:generator-ng-fullstack,代碼行數:12,代碼來源:routes.conf.ts

示例4: initialize

    // -------------------------------------------------------------------------
    // Public Methods
    // -------------------------------------------------------------------------

    /**
     * Initializes the things driver needs before routes and middleware registration.
     */
    initialize() {
        const bodyParser = require("koa-bodyparser");
        this.koa.use(bodyParser());
        if (this.cors) {
            const cors = require("kcors");
            if (this.cors === true) {
                this.koa.use(cors());
            } else {
                this.koa.use(cors(this.cors));
            }
        }
    }
開發者ID:MrDataScientist,項目名稱:routing-controllers,代碼行數:19,代碼來源:KoaDriver.ts

示例5: ServerService

export const ServerServiceFactory = (sm: ServiceManagerInterface) => {
  const config     = sm.get(Config).of<ServerConfigInterface>('server');
  const middleware = [
    sm.get(RequestMiddleware),
    bodyParser(),
    sm.get(RouterMiddleware),
    sm.get(DispatchMiddleware),
  ];

  if (config.cors.enabled) {
    middleware.unshift(cors(config.cors.options));
  }

  return new ServerService(sm.get(Application).getMode(), config, middleware);
};
開發者ID:SpoonX,項目名稱:stix,代碼行數:15,代碼來源:ServerServiceFactory.ts

示例6: createServer

function createServer() {
  const app = new Koa();
  app.use(bodyParser());
  app.use(cors());
  app.use(staticFiles(path.join(__dirname, 'public')));

  const router = new Router();
  router.get('/api/animals', async (ctx) => {
    ctx.body =  [
      {id: 1, name: 'cat'},
      {id: 2, name: 'dog'},
      {id: 3, name: 'fish'}
    ];
  });

  app.use(async (ctx, next) => {
    try {
      await next();
    } catch (err) {

      const error = {
        errorType: 'UNHANDLED_ERROR',
        message: err.message,
        stack: err.stack
      };

      ctx.body = error;
      // tslint:disable-next-line:no-console
      console.error(error);
    }
  });

  app
  .use(router.routes())
  .use(router.allowedMethods());

  return app;
}
開發者ID:stevejhiggs,項目名稱:macgyver,代碼行數:38,代碼來源:server.ts

示例7: require

import 'isomorphic-fetch'
import * as Koa from 'koa'
import { setRouters } from './decorators/router'
import { AppRouter } from './router'
import OAuth from './oauth'
import { setHeaders } from 'teambition-sdk'
const bodyParser = require('koa-bodyparser')

const app = new Koa()

app.use(bodyParser())

app.use(async (ctx, next) => {
  const cookie = await OAuth.getCookie()
    .catch(e => {
      console.error(e)
    })
  if (!cookie) {
    ctx.status = 500
    ctx.body = 'OAuth error'
  } else {
    setHeaders({
      cookie: cookie,
      Accept: 'application/json',
      referer: 'https://www.teambition.com/projects',
      'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2809.0 Safari/537.36'
    })
  }
  next()
})
開發者ID:Brooooooklyn,項目名稱:Cassanova,代碼行數:30,代碼來源:index.ts

示例8: next

  ctx.body = "";

  logger.accessInfo({
    message: "Log out",
    context: ctx
  });
});

koa.use(async (ctx, next) => {
  if (ctx.request.type === "application/octet-stream")
    ctx.disableBodyParser = true;

  return next();
});

koa.use(koaBodyParser());
router.use("/api", api.routes(), api.allowedMethods());

router.get("/", async ctx => {
  let permissionSets = [];
  if (ctx.state.user && ctx.state.user.roles)
    permissionSets = getPermissionSets(ctx);

  ctx.body = `
  <html>
    <head>
      <title>GenieACS</title>
      <link rel="shortcut icon" type="image/png" href="favicon.png" />
      <link rel="stylesheet" href="app.css">
    </head>
    <body>
開發者ID:zaidka,項目名稱:genieacs,代碼行數:31,代碼來源:ui.ts

示例9: next

  require("dotenv").config();

import github from "./github";
import { slackMiddleware } from "./Slack";
import chalk from "chalk";
import * as Koa from "koa";
import * as debug from "debug";
const log = debug("buildbot");

const koaBodyparser = require("koa-bodyparser");

const app = new Koa();
const port = Number(process.env.PORT) || 5555;

app
  .use(koaBodyparser())
  .use(async (ctx: Koa.Context, next: any) => {
    try {
      await next();
    } catch (err) {
      ctx.status = err.status || 500;
      ctx.body = err.message;
      app.emit("error", err, ctx);
    }
  })
  .use(github)
  .use(slackMiddleware);

app.on("error", err => {
  log(err);
});
開發者ID:ft-interactive,項目名稱:ft-ig-github-project-manager,代碼行數:31,代碼來源:index.ts

示例10: require

declare var require: any;

import {Koakit} from '../../index';

let bodyParser = require('koa-bodyparser');

import './resource/router';
import './basic/router';
import './response/router';
import './middleware/router';
import './rules/router';
import './user/router';

Koakit.start({
  middleware: [
    bodyParser()
  ]
});
開發者ID:iamchairs,項目名稱:koakit,代碼行數:18,代碼來源:index.ts


注:本文中的koa-bodyparser.default函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。