mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-24 05:47:44 +08:00
Add koa-router's Router to koa's Context (#27472)
This commit is contained in:
5
types/koa-router/index.d.ts
vendored
5
types/koa-router/index.d.ts
vendored
@@ -3,6 +3,7 @@
|
||||
// Definitions by: Jerry Chin <https://github.com/hellopao>
|
||||
// Pavel Ivanov <https://github.com/schfkt>
|
||||
// JounQin <https://github.com/JounQin>
|
||||
// Romain Faust <https://github.com/romain-faust>
|
||||
// Definitions: https://github.com/hellopao/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
@@ -51,6 +52,10 @@ declare namespace Router {
|
||||
* url params
|
||||
*/
|
||||
params: any;
|
||||
/**
|
||||
* the router instance
|
||||
*/
|
||||
router: Router;
|
||||
}
|
||||
|
||||
export interface IMiddleware {
|
||||
|
||||
@@ -8,21 +8,27 @@ const router = new Router({
|
||||
});
|
||||
|
||||
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 () {
|
||||
// ...
|
||||
});
|
||||
.param('id', function (id, ctx, next) {
|
||||
next();
|
||||
})
|
||||
.get('/', function (ctx, next) {
|
||||
ctx.body = 'Hello World!';
|
||||
})
|
||||
.get('/users/:id', function (ctx, next) {
|
||||
ctx.body = ctx.router.url('user-accounts', { id: ctx.params.id })
|
||||
})
|
||||
.get('user-accounts', '/users/:id/accounts', function (ctx, next) {
|
||||
// ...
|
||||
})
|
||||
.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";
|
||||
|
||||
Reference in New Issue
Block a user