當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。