本文整理汇总了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())
}
示例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));
示例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;
}
示例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);
示例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
示例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);
示例7: allowedMethods
public allowedMethods() {
return this._router.allowedMethods();
}