当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript koa-convert.default函数代码示例

本文整理汇总了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');
        });
开发者ID:JuHwon,项目名称:ironcrux,代码行数:31,代码来源:app.ts

示例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;
开发者ID:Alexandr-Baluhin,项目名称:nodejs-graphql-template,代码行数:31,代码来源:app.ts

示例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'
    }
});
开发者ID:lleitep3,项目名称:transempregos-portal,代码行数:31,代码来源:app.ts

示例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);
//.........这里部分代码省略.........
开发者ID:kildevaeld,项目名称:assets,代码行数:101,代码来源:server2.ts

示例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);
开发者ID:NextZeus,项目名称:cnode,代码行数:25,代码来源:app.ts

示例6: Session

export function Session (options:SessionOptions = {}): MiddlewareFunc {
    return Convert(GenericSession(options));
}
开发者ID:kildevaeld,项目名称:willburg,代码行数:3,代码来源:session.ts


注:本文中的koa-convert.default函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。