本文整理汇总了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;未经允许,请勿转载。 |
请发表评论