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


TypeScript koa-router.allowedMethods函数代码示例

本文整理汇总了TypeScript中koa-router.allowedMethods函数的典型用法代码示例。如果您正苦于以下问题:TypeScript allowedMethods函数的具体用法?TypeScript allowedMethods怎么用?TypeScript allowedMethods使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了allowedMethods函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: createHttpServer

export function createHttpServer(): HttpServer {
  const koa = new Koa()
  installMiddlewares(koa)
  const router = new KoaRouter()
  koa.use(router.routes())
  koa.use(router.allowedMethods())
  return httpCreateServer(koa.callback())
}
开发者ID:ohjames,项目名称:blaggart,代码行数:8,代码来源:index.ts

示例2: createConnection

createConnection().then(async connection => {

    // create koa app
    const app = new Koa();
    const router = new Router();

    // register all application routes
    AppRoutes.forEach(route => router[route.method](route.path, route.action));

    // run app
    app.use(bodyParser());
    app.use(router.routes());
    app.use(router.allowedMethods());
    app.listen(3000);

    console.log("Koa application is up and running on port 3000");

}).catch(error => console.log("TypeORM connection error: ", error));
开发者ID:willchapin,项目名称:typescript-koa-example,代码行数:18,代码来源:index.ts

示例3: 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

示例4: Router

const router = new Router({
    prefix: "/users"
});

router
  .param('id', function(id, ctx, next) {
    next();
  })
  .get('/', function (ctx, next) {
    ctx.body = 'Hello World!';
  })
  .post('/users', function (ctx, next) {
    // ...
  })
  .put('/users/:id', function (ctx, next) {
    ctx.body = ctx.params.id;
  })
  .del('/users/:id', function () {
    // ...
  });

router.get('user', '/users/:id', function (ctx) {
    ctx.body = "sdsd";
});

app.use(router.routes());
app.use(router.allowedMethods());

app.listen(3000);
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:29,代码来源:koa-router-tests.ts

示例5: Date



// logger

app.use(function *(next){
  const start = new Date().getTime();
  yield next;
  const ms = new Date().getTime() - start;
  console.log('%s %s - %s', this.method, this.url, ms);
});

// Redirect

redirect_router.redirect('/', '/static/main.html');
app.use(redirect_router.routes());
app.use(redirect_router.allowedMethods());

// static

app.use(mount('/static', serve('../frontend/build')));


// responses under /api

router.get('/hello', function *(next) {
  this.body = 'hello';
});


function query_to_linestring(points) {
  // Coerce to array
开发者ID:cyounkins,项目名称:uber-homework,代码行数:29,代码来源:main.ts

示例6: require

/// <reference path="./d.ts/node.d.ts" />
/// <reference path="./d.ts/koa.d.ts" />

import {YabpConfig} from './modules/config/config.ts';

import databaseSetup = require('./modules/db/databaseSetup.ts')
import koa = require('koa');

var router = require('koa-router');
var yabpServer = new koa();

router
  .get("/REST/config/isConfigured", function* (next){
    this.statusCode = 200;
    this.set('Access-Control-Allow-Origin','http://localhost:9000')
    this.body = { isConfigured : false };
  })

yabpServer.use(router.routes()).use(router.allowedMethods());
yabpServer.listen(1988);
开发者ID:Paincraft,项目名称:yabp,代码行数:20,代码来源:yabp.ts

示例7: allowedMethods

 public allowedMethods() {
     return this._router.allowedMethods();
 }
开发者ID:Norgerman,项目名称:Koa-ts,代码行数:3,代码来源:RouterBuilder.ts


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