本文整理匯總了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();
}