本文整理汇总了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)
})
}
示例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();
}
}
示例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));
}
示例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));
}
}
}
示例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);
};
示例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;
}
示例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()
})
示例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>
示例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);
});
示例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()
]
});