本文整理匯總了TypeScript中koa-convert.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了default函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: require
import * as path from 'path';
import serve = require('koa-static');
import favicon = require('koa-favicon');
const convert = require('koa-convert');
const fs = require('co-fs');
var app: Koa = module.exports = new Koa();
var router: KoaRouter = new KoaRouter();
var rootDir = path.join(__dirname, '../../');
var port = process.env.PORT || 8001;
var environment = process.env.NODE_ENV || 'dev';
app.use(RequestTime('X-Response-Time'));
app.use(convert(favicon(__dirname + '/favicon.ico')));
switch (environment) {
case 'build':
//TODO: implement build environment server
break;
default:
console.log('*** DEV ***');
console.log('rootDir: ' + rootDir);
app.use(convert(serve(path.join(rootDir, './src/client'))));
app.use(convert(serve(path.join(rootDir, './'), { hidden: true })));
router.get('/*', function *(ctx: KoaRouter.IRouterContext, next: any) {
this.body = yield fs.readFile(path.join(rootDir, './src/client/index.html'), 'utf-8');
});
示例2: koa
const app = new koa();
const router = new koaRouter();
// Entry Point
router.get('/', entryPoint);
// Request ID creation
app.use(async (ctx, next) => {
process.storage = new Storage([['rid', get(ctx.req.headers, 'x-request-id', uuid())]]);
await next();
});
// CORS?
if (process.env.CORS) {
app.use(koaConvert(koaCors()));
}
// GraphQL
const graphqlMiddleware = graphqlKoa(ctx => ({
schema,
tracing: Boolean(process.env.GRAPHQL_TRACING),
validationRules: [
costAnalysis({
variables: ctx.query,
maximumCost: 1000,
defaultCost: 1,
}),
],
formatError: (error) => {
const { message, locations, path, stack } = error;
示例3: Pug
import { MongoError } from 'mongodb';
const convert = require('koa-convert');
const etag = require('koa-etag');
const conditional = require('koa-conditional-get');
import * as path from 'path';
global.log = require('debug')('trans');
import router from './routes/router';
import { startConnectionAsync, rebuildConnectionAsync } from './connectionManager';
import { Config } from './config';
import { serveStatic } from './staticFiles';
startConnectionAsync();
const app = new Koa();
if (!Config.isTestEnv)
app.use(logger());
app.use(convert(conditional()));
app.use(convert(etag()));
app.use(serveStatic());
app.use(convert(json()));
app.use(bodyParser());
const viewPath = path.resolve(__dirname, 'views');
new Pug({
app: app,
viewPath: viewPath,
noCache: Config.isDevEnv,
pretty: Config.isDevEnv,
locals: {
iconsDir: '/dist/public/images/icons'
}
});
示例4: App
export function App(client:Assets, options: AssetsRouterOptions = {} ) {
let app = new Koa();
let router = new Router();
let p = options.prefix|| '/'
router.post(p, convert(body({multipart:true})), createAsset);
router.get(p, listAssets);
router.get(Path.join(p, '*'), getAsset);
router.del(Path.join(p, '*'), deleteAsset);
app.use(convert(cors({
origin: '*',
expose: ['Link']
//expose: 'Content-Type'
})))
app.use(router.routes());
//app.use(router.allowedMethods())
//router.put('/')
return app;
async function listAssets(ctx: Koa.Context) {
ctx.type = 'json';
let query = ctx.query;
if (query.id) {
let asset = await client.getById(query.id);
if (!asset) {
ctx.throw(404, {message:'not found'});
}
ctx.body = asset;
}
let page = 1, limit = 100;
if (query.page) {
let i = parseInt(query.page);
if (!isNaN(i)) page = i;
}
if (query.limit) {
let i = parseInt(query.limit);
if (!isNaN(i)) limit = i;
}
if (page <= 0) page = 1;
let result;
if (query.q) {
result = await client.query(query.q);
} else {
let count = await client.metaStore.count();
let pages = Math.ceil(count / limit);
let offset = limit * (page - 1);
if (offset > count) {
result = [];
} else {
result = await client.list({
offset: offset,
limit: limit
});
}
let links: any = {
first: 1,
last: pages
};
if (page > 1) links.prev = page - 1;
if (page < pages) links.next = page + 1;
_writeLinksHeader(ctx, links);
}
ctx.body = result;
}
async function getAsset(ctx: Koa.Context) {
let query = ctx.query
let path = ctx.path;
if (path[0] !== '/') path = "/" + path;
let asset = (await client.getByPath(path));
console.log(asset)
if (!asset) ctx.throw(404);
//.........這裏部分代碼省略.........
示例5: next
"use strict";
import {resolve} from "path";
import * as Koa from "koa";
const convert = require('koa-convert');
const statics = require('koa-static');
import router from "./config/routes";
const app = new Koa();
app.use(async function (ctx,next) {
try {
await next();
} catch (err) {
console.log(err);
}
});
app.use(convert(statics(resolve(__dirname,'../dist'))));
app.use(router.routes());
app.listen(process.env.PORT || 3000);
示例6: Session
export function Session (options:SessionOptions = {}): MiddlewareFunc {
return Convert(GenericSession(options));
}