• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript koa-passport.authenticate函数代码示例发布时间:2022-05-25
下一篇:
TypeScript koa-compress.default函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap