@tsed/platform-koa 7.0.0-beta.13 → 7.0.0-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jest.config.js +2 -2
- package/lib/cjs/components/PlatformKoa.js +39 -26
- package/lib/cjs/components/PlatformKoa.js.map +1 -1
- package/lib/cjs/index.js +0 -3
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/middlewares/resourceNotFoundMiddleware.js +2 -1
- package/lib/cjs/middlewares/resourceNotFoundMiddleware.js.map +1 -1
- package/lib/cjs/services/PlatformKoaHandler.js +14 -42
- package/lib/cjs/services/PlatformKoaHandler.js.map +1 -1
- package/lib/cjs/services/PlatformKoaRequest.js +1 -1
- package/lib/cjs/services/PlatformKoaRequest.js.map +1 -1
- package/lib/esm/components/PlatformKoa.js +40 -27
- package/lib/esm/components/PlatformKoa.js.map +1 -1
- package/lib/esm/index.js +0 -3
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/middlewares/resourceNotFoundMiddleware.js +2 -1
- package/lib/esm/middlewares/resourceNotFoundMiddleware.js.map +1 -1
- package/lib/esm/services/PlatformKoaHandler.js +15 -43
- package/lib/esm/services/PlatformKoaHandler.js.map +1 -1
- package/lib/esm/services/PlatformKoaRequest.js +1 -1
- package/lib/esm/services/PlatformKoaRequest.js.map +1 -1
- package/lib/types/components/PlatformKoa.d.ts +9 -11
- package/lib/types/index.d.ts +0 -3
- package/lib/types/services/PlatformKoaHandler.d.ts +4 -7
- package/package.json +11 -11
- package/lib/cjs/decorators/caseSensitive.js +0 -30
- package/lib/cjs/decorators/caseSensitive.js.map +0 -1
- package/lib/cjs/decorators/routerSettings.js +0 -31
- package/lib/cjs/decorators/routerSettings.js.map +0 -1
- package/lib/cjs/decorators/strict.js +0 -31
- package/lib/cjs/decorators/strict.js.map +0 -1
- package/lib/esm/decorators/caseSensitive.js +0 -26
- package/lib/esm/decorators/caseSensitive.js.map +0 -1
- package/lib/esm/decorators/routerSettings.js +0 -27
- package/lib/esm/decorators/routerSettings.js.map +0 -1
- package/lib/esm/decorators/strict.js +0 -27
- package/lib/esm/decorators/strict.js.map +0 -1
- package/lib/types/decorators/caseSensitive.d.ts +0 -22
- package/lib/types/decorators/routerSettings.d.ts +0 -24
- package/lib/types/decorators/strict.d.ts +0 -23
package/jest.config.js
CHANGED
|
@@ -74,29 +74,50 @@ class PlatformKoa {
|
|
|
74
74
|
}
|
|
75
75
|
onInit() {
|
|
76
76
|
const injector = this.injector;
|
|
77
|
-
const app = this.
|
|
77
|
+
const app = this.getPlatformApplication();
|
|
78
78
|
const listener = (error, ctx) => {
|
|
79
|
-
|
|
79
|
+
const $ctx = (0, common_1.getContext)();
|
|
80
|
+
injector.get(platform_exceptions_1.PlatformExceptions)?.catch(error, $ctx);
|
|
80
81
|
};
|
|
81
82
|
app.getApp().silent = true;
|
|
82
83
|
app.getApp().on("error", listener);
|
|
83
84
|
}
|
|
84
|
-
|
|
85
|
+
async beforeLoadRoutes() {
|
|
85
86
|
const app = this.injector.get(common_1.PlatformApplication);
|
|
86
|
-
|
|
87
|
-
app.
|
|
88
|
-
|
|
87
|
+
this.useContext();
|
|
88
|
+
app.use(resourceNotFoundMiddleware_1.resourceNotFoundMiddleware);
|
|
89
|
+
}
|
|
90
|
+
mapLayers(layers) {
|
|
91
|
+
const { settings } = this.injector;
|
|
92
|
+
const app = this.getPlatformApplication();
|
|
93
|
+
const options = settings.get("koa.router", {});
|
|
94
|
+
const rawRouter = new router_1.default(options);
|
|
95
|
+
layers.forEach((layer) => {
|
|
96
|
+
switch (layer.method) {
|
|
97
|
+
case "statics":
|
|
98
|
+
rawRouter.use(layer.path, this.statics(layer.path, layer.opts));
|
|
99
|
+
break;
|
|
100
|
+
default:
|
|
101
|
+
rawRouter[layer.method](...layer.getArgs());
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
app.getApp().use(rawRouter.routes()).use(rawRouter.allowedMethods());
|
|
105
|
+
}
|
|
106
|
+
mapHandler(handler, metadata) {
|
|
107
|
+
if (metadata.isRawMiddleware()) {
|
|
108
|
+
return handler;
|
|
109
|
+
}
|
|
110
|
+
return async (koaContext, next) => {
|
|
111
|
+
const $ctx = (0, common_1.getContext)();
|
|
112
|
+
$ctx.next = next;
|
|
113
|
+
await handler($ctx);
|
|
114
|
+
};
|
|
89
115
|
}
|
|
90
116
|
useContext() {
|
|
91
|
-
const app = this.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
app.getApp().use(async (ctx, next) => {
|
|
96
|
-
await invoke({
|
|
97
|
-
request: ctx.request,
|
|
98
|
-
response: ctx.response
|
|
99
|
-
});
|
|
117
|
+
const app = this.getPlatformApplication();
|
|
118
|
+
app.use(async (koaContext, next) => {
|
|
119
|
+
const $ctx = (0, common_1.getContext)();
|
|
120
|
+
$ctx.upgrade({ request: koaContext.request, response: koaContext.response, koaContext });
|
|
100
121
|
return next();
|
|
101
122
|
});
|
|
102
123
|
return this;
|
|
@@ -111,17 +132,6 @@ class PlatformKoa {
|
|
|
111
132
|
}
|
|
112
133
|
};
|
|
113
134
|
}
|
|
114
|
-
router(routerOptions = {}) {
|
|
115
|
-
const { settings } = this.injector;
|
|
116
|
-
const options = Object.assign({}, settings.get("koa.router", {}), routerOptions);
|
|
117
|
-
const router = new router_1.default(options);
|
|
118
|
-
return {
|
|
119
|
-
router,
|
|
120
|
-
callback() {
|
|
121
|
-
return [router.routes(), router.allowedMethods()];
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
135
|
multipart(options) {
|
|
126
136
|
return (0, multer_1.getMulter)(options);
|
|
127
137
|
}
|
|
@@ -138,6 +148,9 @@ class PlatformKoa {
|
|
|
138
148
|
}
|
|
139
149
|
return parser({ ...options, ...additionalOptions });
|
|
140
150
|
}
|
|
151
|
+
getPlatformApplication() {
|
|
152
|
+
return this.injector.get(common_1.PlatformApplication);
|
|
153
|
+
}
|
|
141
154
|
}
|
|
142
155
|
exports.PlatformKoa = PlatformKoa;
|
|
143
156
|
//# sourceMappingURL=PlatformKoa.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":";;;;AAAA,iEAAyE;AACzE,
|
|
1
|
+
{"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":";;;;AAAA,iEAAyE;AACzE,yCAasB;AACtB,mEAA6D;AAC7D,qCAA4C;AAE5C,sDAAuC;AACvC,4EAAsD;AACtD,aAAa;AACb,4DAA2B;AAE3B,0FAAqF;AACrF,wEAAmE;AACnE,uEAAkE;AAClE,uEAAkE;AAClE,yEAAoE;AACpE,4CAA0C;AAgB1C,aAAa;AACb,gBAAS,CAAC,SAAS,CAAC,OAAO,GAAG,gBAAS,CAAC,SAAS,CAAC,KAAK,CAAC;AACxD,gBAAS,CAAC,SAAS,CAAC,KAAK,GAAG,SAAS,KAAK,CAAC,GAAG,IAAW;IACvD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IACtC,IAAI,OAAO,EAAE;QACX,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE;YACvB,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;SACtB;KACF;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAa,WAAW;IAgBF;IAfX,SAAS,GAAG;QACnB;YACE,OAAO,EAAE,yBAAgB;YACzB,QAAQ,EAAE,yCAAmB;SAC9B;QACD;YACE,OAAO,EAAE,wBAAe;YACxB,QAAQ,EAAE,uCAAkB;SAC7B;QACD;YACE,OAAO,EAAE,wBAAe;YACxB,QAAQ,EAAE,uCAAkB;SAC7B;KACF,CAAC;IAEF,YAAoB,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;IAAG,CAAC;IAEjD;;;;OAIG;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["import KoaRouter, {RouterOptions as KoaRouterOptions} from \"@koa/router\";\nimport {\n getContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformContext,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRequest,\n PlatformResponse,\n PlatformStaticsOptions\n} from \"@tsed/common\";\nimport {PlatformExceptions} from \"@tsed/platform-exceptions\";\nimport {isFunction, Type} from \"@tsed/core\";\nimport {PlatformHandlerMetadata, PlatformLayer} from \"@tsed/platform-router\";\nimport Koa, {Context, Next} from \"koa\";\nimport koaBodyParser, {Options} from \"koa-bodyparser\";\n// @ts-ignore\nimport koaQs from \"koa-qs\";\nimport send from \"koa-send\";\nimport {resourceNotFoundMiddleware} from \"../middlewares/resourceNotFoundMiddleware\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\nimport {PlatformKoaHandler} from \"../services/PlatformKoaHandler\";\nimport {PlatformKoaRequest} from \"../services/PlatformKoaRequest\";\nimport {PlatformKoaResponse} from \"../services/PlatformKoaResponse\";\nimport {getMulter} from \"../utils/multer\";\n\ndeclare global {\n namespace TsED {\n export interface Application extends Koa {}\n }\n\n namespace TsED {\n // export interface Router extends KoaRouter {}\n\n export interface RouterOptions extends KoaRouterOptions {}\n\n export interface StaticsOptions extends send.SendOptions {}\n }\n}\n\n// @ts-ignore\nKoaRouter.prototype.$$match = KoaRouter.prototype.match;\nKoaRouter.prototype.match = function match(...args: any[]) {\n const matched = this.$$match(...args);\n if (matched) {\n if (matched.path.length) {\n matched.route = true;\n }\n }\n\n return matched;\n};\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoa implements PlatformAdapter<Koa> {\n readonly providers = [\n {\n provide: PlatformResponse,\n useClass: PlatformKoaResponse\n },\n {\n provide: PlatformRequest,\n useClass: PlatformKoaRequest\n },\n {\n provide: PlatformHandler,\n useClass: PlatformKoaHandler\n }\n ];\n\n constructor(private injector: InjectorService) {}\n\n /**\n * Create new serverless application. In this mode, the component scan are disabled.\n * @param module\n * @param settings\n */\n static create(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.create<Koa>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.bootstrap<Koa>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n onInit() {\n const injector = this.injector;\n const app = this.getPlatformApplication();\n\n const listener: any = (error: any, ctx: Koa.Context) => {\n const $ctx = getContext<PlatformContext>()!;\n injector.get<PlatformExceptions>(PlatformExceptions)?.catch(error, $ctx);\n };\n\n app.getApp().silent = true;\n app.getApp().on(\"error\", listener);\n }\n\n async beforeLoadRoutes() {\n const app = this.injector.get<PlatformApplication<Koa>>(PlatformApplication)!;\n\n this.useContext();\n\n app.use(resourceNotFoundMiddleware);\n }\n\n mapLayers(layers: PlatformLayer[]) {\n const {settings} = this.injector;\n const app = this.getPlatformApplication();\n const options = settings.get(\"koa.router\", {});\n const rawRouter = new KoaRouter(options) as any;\n\n layers.forEach((layer) => {\n switch (layer.method) {\n case \"statics\":\n rawRouter.use(layer.path, this.statics(layer.path as string, layer.opts as any));\n break;\n\n default:\n rawRouter[layer.method](...layer.getArgs());\n }\n });\n\n app.getApp().use(rawRouter.routes()).use(rawRouter.allowedMethods());\n }\n\n mapHandler(handler: Function, metadata: PlatformHandlerMetadata) {\n if (metadata.isRawMiddleware()) {\n return handler;\n }\n\n return async (koaContext: Koa.Context, next: Koa.Next) => {\n const $ctx = getContext<PlatformContext>()!;\n $ctx.next = next;\n\n await handler($ctx);\n };\n }\n\n useContext(): this {\n const app = this.getPlatformApplication();\n\n app.use(async (koaContext: Context, next: Next) => {\n const $ctx = getContext<PlatformContext<PlatformKoaRequest, PlatformKoaResponse>>()!;\n\n $ctx.upgrade({request: koaContext.request as any, response: koaContext.response as any, koaContext});\n\n return next();\n });\n\n return this;\n }\n\n app() {\n const app = this.injector.settings.get(\"koa.app\") || new Koa();\n koaQs(app, \"extended\");\n\n return {\n app,\n callback() {\n return app.callback();\n }\n };\n }\n\n multipart(options: PlatformMulterSettings): PlatformMulter {\n return getMulter(options);\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions) {\n return staticsMiddleware(options);\n }\n\n bodyParser(type: \"json\" | \"urlencoded\" | \"raw\" | \"text\", additionalOptions: any = {}): any {\n const opts = this.injector.settings.get(`koa.bodyParser`);\n let parser: any = koaBodyParser;\n\n let options: Options = {};\n\n if (isFunction(opts)) {\n parser = opts;\n options = {};\n }\n\n return parser({...options, ...additionalOptions});\n }\n\n private getPlatformApplication() {\n return this.injector.get<PlatformApplication>(PlatformApplication)!;\n }\n}\n"]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -6,11 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const tslib_1 = require("tslib");
|
|
7
7
|
tslib_1.__exportStar(require("./exports"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./components/PlatformKoa"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./decorators/caseSensitive"), exports);
|
|
10
9
|
tslib_1.__exportStar(require("./decorators/ctx"), exports);
|
|
11
|
-
tslib_1.__exportStar(require("./decorators/routerSettings"), exports);
|
|
12
10
|
tslib_1.__exportStar(require("./decorators/state"), exports);
|
|
13
|
-
tslib_1.__exportStar(require("./decorators/strict"), exports);
|
|
14
11
|
tslib_1.__exportStar(require("./interfaces/PlatformKoaSettings"), exports);
|
|
15
12
|
tslib_1.__exportStar(require("./interfaces/interfaces"), exports);
|
|
16
13
|
tslib_1.__exportStar(require("./middlewares/resourceNotFoundMiddleware"), exports);
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,oDAA0B;AAC1B,mEAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,oDAA0B;AAC1B,mEAAyC;AACzC,2DAAiC;AACjC,6DAAmC;AACnC,2EAAiD;AACjD,kEAAwC;AACxC,mFAAyD;AACzD,0EAAgD;AAChD,wEAA8C;AAC9C,wEAA8C;AAC9C,yEAA+C;AAC/C,yDAA+B","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./exports\";\nexport * from \"./components/PlatformKoa\";\nexport * from \"./decorators/ctx\";\nexport * from \"./decorators/state\";\nexport * from \"./interfaces/PlatformKoaSettings\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./middlewares/resourceNotFoundMiddleware\";\nexport * from \"./middlewares/staticsMiddleware\";\nexport * from \"./services/PlatformKoaHandler\";\nexport * from \"./services/PlatformKoaRequest\";\nexport * from \"./services/PlatformKoaResponse\";\nexport * from \"./utils/multer\";\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resourceNotFoundMiddleware = void 0;
|
|
4
|
+
const di_1 = require("@tsed/di");
|
|
4
5
|
const platform_exceptions_1 = require("@tsed/platform-exceptions");
|
|
5
6
|
/**
|
|
6
7
|
* @ignore
|
|
@@ -8,7 +9,7 @@ const platform_exceptions_1 = require("@tsed/platform-exceptions");
|
|
|
8
9
|
* @param next
|
|
9
10
|
*/
|
|
10
11
|
async function resourceNotFoundMiddleware(ctx, next) {
|
|
11
|
-
const $ctx =
|
|
12
|
+
const $ctx = (0, di_1.getContext)();
|
|
12
13
|
await next();
|
|
13
14
|
const status = ctx.status || 404;
|
|
14
15
|
if (status === 404 && !$ctx.isDone()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resourceNotFoundMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/resourceNotFoundMiddleware.ts"],"names":[],"mappings":";;;AACA,mEAA6D;AAE7D;;;;GAIG;AACI,KAAK,UAAU,0BAA0B,CAAC,GAAQ,EAAE,IAAS;IAClE,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"resourceNotFoundMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/resourceNotFoundMiddleware.ts"],"names":[],"mappings":";;;AACA,iCAAoC;AACpC,mEAA6D;AAE7D;;;;GAIG;AACI,KAAK,UAAU,0BAA0B,CAAC,GAAQ,EAAE,IAAS;IAClE,MAAM,IAAI,GAAG,IAAA,eAAU,GAAoB,CAAC;IAC5C,MAAM,IAAI,EAAE,CAAC;IACb,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC;IAEjC,IAAI,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE;QACpC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAqB,wCAAkB,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;KACnF;AACH,CAAC;AARD,gEAQC","sourcesContent":["import {PlatformContext} from \"@tsed/common\";\nimport {getContext} from \"@tsed/di\";\nimport {PlatformExceptions} from \"@tsed/platform-exceptions\";\n\n/**\n * @ignore\n * @param ctx\n * @param next\n */\nexport async function resourceNotFoundMiddleware(ctx: any, next: any) {\n const $ctx = getContext<PlatformContext>()!;\n await next();\n const status = ctx.status || 404;\n\n if (status === 404 && !$ctx.isDone()) {\n $ctx.injector.get<PlatformExceptions>(PlatformExceptions)?.resourceNotFound($ctx);\n }\n}\n"]}
|
|
@@ -2,58 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PlatformKoaHandler = void 0;
|
|
4
4
|
const common_1 = require("@tsed/common");
|
|
5
|
+
const core_1 = require("@tsed/core");
|
|
5
6
|
require("./PlatformKoaRequest");
|
|
6
|
-
const OVERRIDE_TYPES = [common_1.HandlerType.ENDPOINT, common_1.HandlerType.MIDDLEWARE, common_1.HandlerType.ERR_MIDDLEWARE, common_1.HandlerType.CTX_FN];
|
|
7
7
|
class PlatformKoaHandler extends common_1.PlatformHandler {
|
|
8
|
-
async flush(
|
|
9
|
-
if (data === undefined && ctx.getResponse().body) {
|
|
10
|
-
data = ctx.getResponse().body;
|
|
8
|
+
async flush($ctx) {
|
|
9
|
+
if ($ctx.data === undefined && $ctx.getResponse().body) {
|
|
10
|
+
$ctx.data = $ctx.getResponse().body;
|
|
11
11
|
}
|
|
12
|
-
return super.flush(
|
|
12
|
+
return super.flush($ctx);
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
return async (ctx, next) => handler({ next, $ctx: ctx.request.$ctx });
|
|
18
|
-
}
|
|
19
|
-
return super.createRawHandler(metadata);
|
|
20
|
-
}
|
|
21
|
-
async onRequest(requestOptions) {
|
|
22
|
-
const { metadata, $ctx } = requestOptions;
|
|
23
|
-
if ($ctx.data instanceof Error) {
|
|
24
|
-
if (metadata.hasErrorParam) {
|
|
25
|
-
requestOptions.err = $ctx.data;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
return this.onError($ctx.data, requestOptions);
|
|
29
|
-
}
|
|
14
|
+
async onRequest(handler, $ctx) {
|
|
15
|
+
if ($ctx.error instanceof Error && !$ctx.handlerMetadata.hasErrorParam) {
|
|
16
|
+
return;
|
|
30
17
|
}
|
|
31
|
-
return super.onRequest(
|
|
18
|
+
return super.onRequest(handler, $ctx);
|
|
32
19
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// istanbul ignore next
|
|
36
|
-
if ($ctx.isDone()) {
|
|
20
|
+
next(error, next, $ctx) {
|
|
21
|
+
if ((0, core_1.isStream)($ctx.data) || $ctx.isDone()) {
|
|
37
22
|
return;
|
|
38
23
|
}
|
|
39
|
-
$ctx.
|
|
40
|
-
|
|
41
|
-
this.throwError(error, $ctx);
|
|
24
|
+
if (error && !($ctx.handlerMetadata.isEndpoint() && !$ctx.handlerMetadata.isFinal())) {
|
|
25
|
+
$ctx.getApp().emit("error", error, $ctx.getRequest().ctx);
|
|
42
26
|
return;
|
|
43
27
|
}
|
|
44
|
-
return next();
|
|
45
|
-
}
|
|
46
|
-
async onCtxRequest(requestOptions) {
|
|
47
|
-
const { $ctx } = requestOptions;
|
|
48
|
-
try {
|
|
49
|
-
return await super.onCtxRequest(requestOptions);
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
this.throwError(error, $ctx);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
throwError(error, $ctx) {
|
|
56
|
-
$ctx.getApp().emit("error", error, $ctx.getRequest().ctx);
|
|
28
|
+
return !$ctx.handlerMetadata.isFinal() && next();
|
|
57
29
|
}
|
|
58
30
|
}
|
|
59
31
|
exports.PlatformKoaHandler = PlatformKoaHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaHandler.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"PlatformKoaHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaHandler.ts"],"names":[],"mappings":";;;AAAA,yCAAsF;AACtF,qCAAoC;AAEpC,gCAA8B;AAE9B,MAAa,kBAAmB,SAAQ,wBAAe;IAC9C,KAAK,CAAC,KAAK,CAAC,IAAqB;QACtC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE;YACtD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC;SACrC;QAED,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,OAA+B,EAAE,IAAqB;QACpE,IAAI,IAAI,CAAC,KAAK,YAAY,KAAK,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE;YACtE,OAAO;SACR;QAED,OAAO,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACxC,CAAC;IAEM,IAAI,CAAC,KAAc,EAAE,IAAS,EAAE,IAAqB;QAC1D,IAAI,IAAA,eAAQ,EAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE;YACxC,OAAO;SACR;QAED,IAAI,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC,EAAE;YACpF,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;YAC1D,OAAO;SACR;QAED,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC;IACnD,CAAC;CACF;AA7BD,gDA6BC","sourcesContent":["import {PlatformContext, PlatformHandler, PlatformParamsCallback} from \"@tsed/common\";\nimport {isStream} from \"@tsed/core\";\nimport {PlatformContextHandler} from \"@tsed/platform-router\";\nimport \"./PlatformKoaRequest\";\n\nexport class PlatformKoaHandler extends PlatformHandler {\n public async flush($ctx: PlatformContext) {\n if ($ctx.data === undefined && $ctx.getResponse().body) {\n $ctx.data = $ctx.getResponse().body;\n }\n\n return super.flush($ctx);\n }\n\n async onRequest(handler: PlatformParamsCallback, $ctx: PlatformContext): Promise<any> {\n if ($ctx.error instanceof Error && !$ctx.handlerMetadata.hasErrorParam) {\n return;\n }\n\n return super.onRequest(handler, $ctx);\n }\n\n public next(error: unknown, next: any, $ctx: PlatformContext) {\n if (isStream($ctx.data) || $ctx.isDone()) {\n return;\n }\n\n if (error && !($ctx.handlerMetadata.isEndpoint() && !$ctx.handlerMetadata.isFinal())) {\n $ctx.getApp().emit(\"error\", error, $ctx.getRequest().ctx);\n return;\n }\n\n return !$ctx.handlerMetadata.isFinal() && next();\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":";;;AAAA,uBAAqB;AACrB,yCAA8D;AAgB9D;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,wBAA4B;IAClE,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":";;;AAAA,uBAAqB;AACrB,yCAA8D;AAgB9D;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,wBAA4B;IAClE,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAyB,CAAC;IACnD,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;IACnC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;IAC/B,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC;IACjC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;IAC7C,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;IAC1B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC;IAC9B,CAAC;CACF;AA5BD,gDA4BC","sourcesContent":["import \"@koa/router\";\nimport {PlatformContext, PlatformRequest} from \"@tsed/common\";\nimport Koa from \"koa\";\n\ndeclare module \"koa\" {\n export interface Request {\n id: string;\n $ctx: PlatformContext;\n }\n}\n\ndeclare global {\n namespace TsED {\n export interface Request extends Koa.Request {}\n }\n}\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoaRequest extends PlatformRequest<Koa.Request> {\n get ctx(): Koa.Context {\n return this.$ctx.event.koaContext as Koa.Context;\n }\n\n get protocol(): string {\n return this.ctx.request.protocol;\n }\n\n get host(): string {\n return this.ctx.request.host;\n }\n\n get secure(): boolean {\n return this.ctx.request.secure;\n }\n\n get cookies(): {[p: string]: any} {\n return this.ctx.cookie || this.ctx.cookies;\n }\n\n get session(): any {\n return this.ctx.session;\n }\n\n getReq() {\n return this.ctx.request.req;\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import KoaRouter from "@koa/router";
|
|
2
|
-
import {
|
|
2
|
+
import { getContext, PlatformApplication, PlatformBuilder, PlatformHandler, PlatformRequest, PlatformResponse } from "@tsed/common";
|
|
3
3
|
import { PlatformExceptions } from "@tsed/platform-exceptions";
|
|
4
4
|
import { isFunction } from "@tsed/core";
|
|
5
5
|
import Koa from "koa";
|
|
@@ -70,29 +70,50 @@ export class PlatformKoa {
|
|
|
70
70
|
}
|
|
71
71
|
onInit() {
|
|
72
72
|
const injector = this.injector;
|
|
73
|
-
const app = this.
|
|
73
|
+
const app = this.getPlatformApplication();
|
|
74
74
|
const listener = (error, ctx) => {
|
|
75
|
-
|
|
75
|
+
const $ctx = getContext();
|
|
76
|
+
injector.get(PlatformExceptions)?.catch(error, $ctx);
|
|
76
77
|
};
|
|
77
78
|
app.getApp().silent = true;
|
|
78
79
|
app.getApp().on("error", listener);
|
|
79
80
|
}
|
|
80
|
-
|
|
81
|
+
async beforeLoadRoutes() {
|
|
81
82
|
const app = this.injector.get(PlatformApplication);
|
|
82
|
-
|
|
83
|
-
app.
|
|
84
|
-
|
|
83
|
+
this.useContext();
|
|
84
|
+
app.use(resourceNotFoundMiddleware);
|
|
85
|
+
}
|
|
86
|
+
mapLayers(layers) {
|
|
87
|
+
const { settings } = this.injector;
|
|
88
|
+
const app = this.getPlatformApplication();
|
|
89
|
+
const options = settings.get("koa.router", {});
|
|
90
|
+
const rawRouter = new KoaRouter(options);
|
|
91
|
+
layers.forEach((layer) => {
|
|
92
|
+
switch (layer.method) {
|
|
93
|
+
case "statics":
|
|
94
|
+
rawRouter.use(layer.path, this.statics(layer.path, layer.opts));
|
|
95
|
+
break;
|
|
96
|
+
default:
|
|
97
|
+
rawRouter[layer.method](...layer.getArgs());
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
app.getApp().use(rawRouter.routes()).use(rawRouter.allowedMethods());
|
|
101
|
+
}
|
|
102
|
+
mapHandler(handler, metadata) {
|
|
103
|
+
if (metadata.isRawMiddleware()) {
|
|
104
|
+
return handler;
|
|
105
|
+
}
|
|
106
|
+
return async (koaContext, next) => {
|
|
107
|
+
const $ctx = getContext();
|
|
108
|
+
$ctx.next = next;
|
|
109
|
+
await handler($ctx);
|
|
110
|
+
};
|
|
85
111
|
}
|
|
86
112
|
useContext() {
|
|
87
|
-
const app = this.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
app.getApp().use(async (ctx, next) => {
|
|
92
|
-
await invoke({
|
|
93
|
-
request: ctx.request,
|
|
94
|
-
response: ctx.response
|
|
95
|
-
});
|
|
113
|
+
const app = this.getPlatformApplication();
|
|
114
|
+
app.use(async (koaContext, next) => {
|
|
115
|
+
const $ctx = getContext();
|
|
116
|
+
$ctx.upgrade({ request: koaContext.request, response: koaContext.response, koaContext });
|
|
96
117
|
return next();
|
|
97
118
|
});
|
|
98
119
|
return this;
|
|
@@ -107,17 +128,6 @@ export class PlatformKoa {
|
|
|
107
128
|
}
|
|
108
129
|
};
|
|
109
130
|
}
|
|
110
|
-
router(routerOptions = {}) {
|
|
111
|
-
const { settings } = this.injector;
|
|
112
|
-
const options = Object.assign({}, settings.get("koa.router", {}), routerOptions);
|
|
113
|
-
const router = new KoaRouter(options);
|
|
114
|
-
return {
|
|
115
|
-
router,
|
|
116
|
-
callback() {
|
|
117
|
-
return [router.routes(), router.allowedMethods()];
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
131
|
multipart(options) {
|
|
122
132
|
return getMulter(options);
|
|
123
133
|
}
|
|
@@ -134,5 +144,8 @@ export class PlatformKoa {
|
|
|
134
144
|
}
|
|
135
145
|
return parser({ ...options, ...additionalOptions });
|
|
136
146
|
}
|
|
147
|
+
getPlatformApplication() {
|
|
148
|
+
return this.injector.get(PlatformApplication);
|
|
149
|
+
}
|
|
137
150
|
}
|
|
138
151
|
//# sourceMappingURL=PlatformKoa.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":"AAAA,OAAO,SAA8C,MAAM,aAAa,CAAC;AACzE,OAAO,EACL,aAAa,EAGb,mBAAmB,EACnB,eAAe,EACf,eAAe,EAGf,eAAe,EACf,gBAAgB,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,kBAAkB,EAAC,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAC,UAAU,EAAO,MAAM,YAAY,CAAC;AAC5C,OAAO,GAAoB,MAAM,KAAK,CAAC;AACvC,OAAO,aAAwB,MAAM,gBAAgB,CAAC;AACtD,aAAa;AACb,OAAO,KAAK,MAAM,QAAQ,CAAC;AAE3B,OAAO,EAAC,0BAA0B,EAAC,MAAM,2CAA2C,CAAC;AACrF,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAC,mBAAmB,EAAC,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAA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C;QAE1B,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE;YACpB,MAAM,GAAG,IAAI,CAAC;YACd,OAAO,GAAG,EAAE,CAAC;SACd;QAED,OAAO,MAAM,CAAC,EAAC,GAAG,OAAO,EAAE,GAAG,iBAAiB,EAAC,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["import KoaRouter, {RouterOptions as KoaRouterOptions} from \"@koa/router\";\nimport {\n createContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRequest,\n PlatformResponse,\n PlatformStaticsOptions\n} from \"@tsed/common\";\nimport {PlatformExceptions} from \"@tsed/platform-exceptions\";\nimport {isFunction, Type} from \"@tsed/core\";\nimport Koa, {Context, Next} from \"koa\";\nimport koaBodyParser, {Options} from \"koa-bodyparser\";\n// @ts-ignore\nimport koaQs from \"koa-qs\";\nimport send from \"koa-send\";\nimport {resourceNotFoundMiddleware} from \"../middlewares/resourceNotFoundMiddleware\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\nimport {PlatformKoaHandler} from \"../services/PlatformKoaHandler\";\nimport {PlatformKoaRequest} from \"../services/PlatformKoaRequest\";\nimport {PlatformKoaResponse} from \"../services/PlatformKoaResponse\";\nimport {getMulter} from \"../utils/multer\";\n\ndeclare global {\n namespace TsED {\n export interface Application extends Koa {}\n }\n\n namespace TsED {\n export interface Router extends KoaRouter {}\n\n export interface RouterOptions extends KoaRouterOptions {}\n\n export interface StaticsOptions extends send.SendOptions {}\n }\n}\n\n// @ts-ignore\nKoaRouter.prototype.$$match = KoaRouter.prototype.match;\nKoaRouter.prototype.match = function match(...args: any[]) {\n const matched = this.$$match(...args);\n if (matched) {\n if (matched.path.length) {\n matched.route = true;\n }\n }\n\n return matched;\n};\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoa implements PlatformAdapter<Koa, KoaRouter> {\n readonly providers = [\n {\n provide: PlatformResponse,\n useClass: PlatformKoaResponse\n },\n {\n provide: PlatformRequest,\n useClass: PlatformKoaRequest\n },\n {\n provide: PlatformHandler,\n useClass: PlatformKoaHandler\n }\n ];\n\n constructor(private injector: InjectorService) {}\n\n /**\n * Create new serverless application. In this mode, the component scan are disabled.\n * @param module\n * @param settings\n */\n static create(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.create<Koa, KoaRouter>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.bootstrap<Koa, KoaRouter>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n onInit() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication>(PlatformApplication)!;\n\n const listener: any = (error: any, ctx: Koa.Context) => {\n injector.get<PlatformExceptions>(PlatformExceptions)?.catch(error, ctx.request.$ctx);\n };\n\n app.getApp().silent = true;\n app.getApp().on(\"error\", listener);\n }\n\n useRouter(): this {\n const app = this.injector.get<PlatformApplication<Koa>>(PlatformApplication)!;\n\n app.getApp().use(resourceNotFoundMiddleware);\n app.getApp().use(app.getRouter().routes()).use(app.getRouter().allowedMethods());\n\n return this;\n }\n\n useContext(): this {\n const app = this.injector.get<PlatformApplication<Koa>>(PlatformApplication)!;\n const {logger} = this.injector;\n logger.info(\"Mount app context\");\n\n const invoke = createContext(this.injector);\n\n app.getApp().use(async (ctx: Context, next: Next) => {\n await invoke({\n request: ctx.request as any,\n response: ctx.response as any\n });\n\n return next();\n });\n\n return this;\n }\n\n app() {\n const app = this.injector.settings.get(\"koa.app\") || new Koa();\n koaQs(app, \"extended\");\n\n return {\n app,\n callback() {\n return app.callback();\n }\n };\n }\n\n router(routerOptions: any = {}) {\n const {settings} = this.injector;\n\n const options = Object.assign({}, settings.get(\"koa.router\", {}), routerOptions);\n const router = new KoaRouter(options) as any;\n\n return {\n router,\n callback() {\n return [router.routes(), router.allowedMethods()];\n }\n };\n }\n\n multipart(options: PlatformMulterSettings): PlatformMulter {\n return getMulter(options);\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions) {\n return staticsMiddleware(options);\n }\n\n bodyParser(type: \"json\" | \"urlencoded\" | \"raw\" | \"text\", additionalOptions: any = {}): any {\n const opts = this.injector.settings.get(`koa.bodyParser`);\n let parser: any = koaBodyParser;\n\n let options: Options = {};\n\n if (isFunction(opts)) {\n parser = opts;\n options = {};\n }\n\n return parser({...options, ...additionalOptions});\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":"AAAA,OAAO,SAA8C,MAAM,aAAa,CAAC;AACzE,OAAO,EACL,UAAU,EAGV,mBAAmB,EACnB,eAAe,EAEf,eAAe,EAGf,eAAe,EACf,gBAAgB,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,kBAAkB,EAAC,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAC,UAAU,EAAO,MAAM,YAAY,CAAC;AAE5C,OAAO,GAAoB,MAAM,KAAK,CAAC;AACvC,OAAO,aAAwB,MAAM,gBAAgB,CAAC;AACtD,aAAa;AACb,OAAO,KAAK,MAAM,QAAQ,CAAC;AAE3B,OAAO,EAAC,0BAA0B,EAAC,MAAM,2CAA2C,CAAC;AACrF,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAC,mBAAmB,EAAC,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAgB1C,aAAa;AACb,SAAS,CAAC,SAAS,CAAC,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC;AACxD,S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ACvD,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAED,UAAU,CAAC,IAA4C,EAAE,oBAAyB,EAAE;QAClF,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC1D,IAAI,MAAM,GAAQ,aAAa,CAAC;QAEhC,IAAI,OAAO,GAAY,EAAE,CAAC;QAE1B,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE;YACpB,MAAM,GAAG,IAAI,CAAC;YACd,OAAO,GAAG,EAAE,CAAC;SACd;QAED,OAAO,MAAM,CAAC,EAAC,GAAG,OAAO,EAAE,GAAG,iBAAiB,EAAC,CAAC,CAAC;IACpD,CAAC;IAEO,sBAAsB;QAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAsB,mBAAmB,CAAE,CAAC;IACtE,CAAC;CACF","sourcesContent":["import KoaRouter, {RouterOptions as KoaRouterOptions} from \"@koa/router\";\nimport {\n getContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformContext,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRequest,\n PlatformResponse,\n PlatformStaticsOptions\n} from \"@tsed/common\";\nimport {PlatformExceptions} from \"@tsed/platform-exceptions\";\nimport {isFunction, Type} from \"@tsed/core\";\nimport {PlatformHandlerMetadata, PlatformLayer} from \"@tsed/platform-router\";\nimport Koa, {Context, Next} from \"koa\";\nimport koaBodyParser, {Options} from \"koa-bodyparser\";\n// @ts-ignore\nimport koaQs from \"koa-qs\";\nimport send from \"koa-send\";\nimport {resourceNotFoundMiddleware} from \"../middlewares/resourceNotFoundMiddleware\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\nimport {PlatformKoaHandler} from \"../services/PlatformKoaHandler\";\nimport {PlatformKoaRequest} from \"../services/PlatformKoaRequest\";\nimport {PlatformKoaResponse} from \"../services/PlatformKoaResponse\";\nimport {getMulter} from \"../utils/multer\";\n\ndeclare global {\n namespace TsED {\n export interface Application extends Koa {}\n }\n\n namespace TsED {\n // export interface Router extends KoaRouter {}\n\n export interface RouterOptions extends KoaRouterOptions {}\n\n export interface StaticsOptions extends send.SendOptions {}\n }\n}\n\n// @ts-ignore\nKoaRouter.prototype.$$match = KoaRouter.prototype.match;\nKoaRouter.prototype.match = function match(...args: any[]) {\n const matched = this.$$match(...args);\n if (matched) {\n if (matched.path.length) {\n matched.route = true;\n }\n }\n\n return matched;\n};\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoa implements PlatformAdapter<Koa> {\n readonly providers = [\n {\n provide: PlatformResponse,\n useClass: PlatformKoaResponse\n },\n {\n provide: PlatformRequest,\n useClass: PlatformKoaRequest\n },\n {\n provide: PlatformHandler,\n useClass: PlatformKoaHandler\n }\n ];\n\n constructor(private injector: InjectorService) {}\n\n /**\n * Create new serverless application. In this mode, the component scan are disabled.\n * @param module\n * @param settings\n */\n static create(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.create<Koa>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.bootstrap<Koa>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n onInit() {\n const injector = this.injector;\n const app = this.getPlatformApplication();\n\n const listener: any = (error: any, ctx: Koa.Context) => {\n const $ctx = getContext<PlatformContext>()!;\n injector.get<PlatformExceptions>(PlatformExceptions)?.catch(error, $ctx);\n };\n\n app.getApp().silent = true;\n app.getApp().on(\"error\", listener);\n }\n\n async beforeLoadRoutes() {\n const app = this.injector.get<PlatformApplication<Koa>>(PlatformApplication)!;\n\n this.useContext();\n\n app.use(resourceNotFoundMiddleware);\n }\n\n mapLayers(layers: PlatformLayer[]) {\n const {settings} = this.injector;\n const app = this.getPlatformApplication();\n const options = settings.get(\"koa.router\", {});\n const rawRouter = new KoaRouter(options) as any;\n\n layers.forEach((layer) => {\n switch (layer.method) {\n case \"statics\":\n rawRouter.use(layer.path, this.statics(layer.path as string, layer.opts as any));\n break;\n\n default:\n rawRouter[layer.method](...layer.getArgs());\n }\n });\n\n app.getApp().use(rawRouter.routes()).use(rawRouter.allowedMethods());\n }\n\n mapHandler(handler: Function, metadata: PlatformHandlerMetadata) {\n if (metadata.isRawMiddleware()) {\n return handler;\n }\n\n return async (koaContext: Koa.Context, next: Koa.Next) => {\n const $ctx = getContext<PlatformContext>()!;\n $ctx.next = next;\n\n await handler($ctx);\n };\n }\n\n useContext(): this {\n const app = this.getPlatformApplication();\n\n app.use(async (koaContext: Context, next: Next) => {\n const $ctx = getContext<PlatformContext<PlatformKoaRequest, PlatformKoaResponse>>()!;\n\n $ctx.upgrade({request: koaContext.request as any, response: koaContext.response as any, koaContext});\n\n return next();\n });\n\n return this;\n }\n\n app() {\n const app = this.injector.settings.get(\"koa.app\") || new Koa();\n koaQs(app, \"extended\");\n\n return {\n app,\n callback() {\n return app.callback();\n }\n };\n }\n\n multipart(options: PlatformMulterSettings): PlatformMulter {\n return getMulter(options);\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions) {\n return staticsMiddleware(options);\n }\n\n bodyParser(type: \"json\" | \"urlencoded\" | \"raw\" | \"text\", additionalOptions: any = {}): any {\n const opts = this.injector.settings.get(`koa.bodyParser`);\n let parser: any = koaBodyParser;\n\n let options: Options = {};\n\n if (isFunction(opts)) {\n parser = opts;\n options = {};\n }\n\n return parser({...options, ...additionalOptions});\n }\n\n private getPlatformApplication() {\n return this.injector.get<PlatformApplication>(PlatformApplication)!;\n }\n}\n"]}
|
package/lib/esm/index.js
CHANGED
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export * from "./exports.js";
|
|
5
5
|
export * from "./components/PlatformKoa.js";
|
|
6
|
-
export * from "./decorators/caseSensitive.js";
|
|
7
6
|
export * from "./decorators/ctx.js";
|
|
8
|
-
export * from "./decorators/routerSettings.js";
|
|
9
7
|
export * from "./decorators/state.js";
|
|
10
|
-
export * from "./decorators/strict.js";
|
|
11
8
|
export * from "./interfaces/PlatformKoaSettings.js";
|
|
12
9
|
export * from "./interfaces/interfaces.js";
|
|
13
10
|
export * from "./middlewares/resourceNotFoundMiddleware.js";
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,0BAA0B,CAAC;AACzC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kCAAkC,CAAC;AACjD,cAAc,yBAAyB,CAAC;AACxC,cAAc,0CAA0C,CAAC;AACzD,cAAc,iCAAiC,CAAC;AAChD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gBAAgB,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./exports\";\nexport * from \"./components/PlatformKoa\";\nexport * from \"./decorators/ctx\";\nexport * from \"./decorators/state\";\nexport * from \"./interfaces/PlatformKoaSettings\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./middlewares/resourceNotFoundMiddleware\";\nexport * from \"./middlewares/staticsMiddleware\";\nexport * from \"./services/PlatformKoaHandler\";\nexport * from \"./services/PlatformKoaRequest\";\nexport * from \"./services/PlatformKoaResponse\";\nexport * from \"./utils/multer\";\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getContext } from "@tsed/di";
|
|
1
2
|
import { PlatformExceptions } from "@tsed/platform-exceptions";
|
|
2
3
|
/**
|
|
3
4
|
* @ignore
|
|
@@ -5,7 +6,7 @@ import { PlatformExceptions } from "@tsed/platform-exceptions";
|
|
|
5
6
|
* @param next
|
|
6
7
|
*/
|
|
7
8
|
export async function resourceNotFoundMiddleware(ctx, next) {
|
|
8
|
-
const $ctx =
|
|
9
|
+
const $ctx = getContext();
|
|
9
10
|
await next();
|
|
10
11
|
const status = ctx.status || 404;
|
|
11
12
|
if (status === 404 && !$ctx.isDone()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resourceNotFoundMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/resourceNotFoundMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,kBAAkB,EAAC,MAAM,2BAA2B,CAAC;AAE7D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,GAAQ,EAAE,IAAS;IAClE,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"resourceNotFoundMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/resourceNotFoundMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AACpC,OAAO,EAAC,kBAAkB,EAAC,MAAM,2BAA2B,CAAC;AAE7D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,GAAQ,EAAE,IAAS;IAClE,MAAM,IAAI,GAAG,UAAU,EAAoB,CAAC;IAC5C,MAAM,IAAI,EAAE,CAAC;IACb,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC;IAEjC,IAAI,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE;QACpC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAqB,kBAAkB,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;KACnF;AACH,CAAC","sourcesContent":["import {PlatformContext} from \"@tsed/common\";\nimport {getContext} from \"@tsed/di\";\nimport {PlatformExceptions} from \"@tsed/platform-exceptions\";\n\n/**\n * @ignore\n * @param ctx\n * @param next\n */\nexport async function resourceNotFoundMiddleware(ctx: any, next: any) {\n const $ctx = getContext<PlatformContext>()!;\n await next();\n const status = ctx.status || 404;\n\n if (status === 404 && !$ctx.isDone()) {\n $ctx.injector.get<PlatformExceptions>(PlatformExceptions)?.resourceNotFound($ctx);\n }\n}\n"]}
|
|
@@ -1,56 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PlatformHandler } from "@tsed/common";
|
|
2
|
+
import { isStream } from "@tsed/core";
|
|
2
3
|
import "./PlatformKoaRequest.js";
|
|
3
|
-
const OVERRIDE_TYPES = [HandlerType.ENDPOINT, HandlerType.MIDDLEWARE, HandlerType.ERR_MIDDLEWARE, HandlerType.CTX_FN];
|
|
4
4
|
export class PlatformKoaHandler extends PlatformHandler {
|
|
5
|
-
async flush(
|
|
6
|
-
if (data === undefined && ctx.getResponse().body) {
|
|
7
|
-
data = ctx.getResponse().body;
|
|
5
|
+
async flush($ctx) {
|
|
6
|
+
if ($ctx.data === undefined && $ctx.getResponse().body) {
|
|
7
|
+
$ctx.data = $ctx.getResponse().body;
|
|
8
8
|
}
|
|
9
|
-
return super.flush(
|
|
9
|
+
return super.flush($ctx);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
return async (ctx, next) => handler({ next, $ctx: ctx.request.$ctx });
|
|
15
|
-
}
|
|
16
|
-
return super.createRawHandler(metadata);
|
|
17
|
-
}
|
|
18
|
-
async onRequest(requestOptions) {
|
|
19
|
-
const { metadata, $ctx } = requestOptions;
|
|
20
|
-
if ($ctx.data instanceof Error) {
|
|
21
|
-
if (metadata.hasErrorParam) {
|
|
22
|
-
requestOptions.err = $ctx.data;
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
return this.onError($ctx.data, requestOptions);
|
|
26
|
-
}
|
|
11
|
+
async onRequest(handler, $ctx) {
|
|
12
|
+
if ($ctx.error instanceof Error && !$ctx.handlerMetadata.hasErrorParam) {
|
|
13
|
+
return;
|
|
27
14
|
}
|
|
28
|
-
return super.onRequest(
|
|
15
|
+
return super.onRequest(handler, $ctx);
|
|
29
16
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// istanbul ignore next
|
|
33
|
-
if ($ctx.isDone()) {
|
|
17
|
+
next(error, next, $ctx) {
|
|
18
|
+
if (isStream($ctx.data) || $ctx.isDone()) {
|
|
34
19
|
return;
|
|
35
20
|
}
|
|
36
|
-
$ctx.
|
|
37
|
-
|
|
38
|
-
this.throwError(error, $ctx);
|
|
21
|
+
if (error && !($ctx.handlerMetadata.isEndpoint() && !$ctx.handlerMetadata.isFinal())) {
|
|
22
|
+
$ctx.getApp().emit("error", error, $ctx.getRequest().ctx);
|
|
39
23
|
return;
|
|
40
24
|
}
|
|
41
|
-
return next();
|
|
42
|
-
}
|
|
43
|
-
async onCtxRequest(requestOptions) {
|
|
44
|
-
const { $ctx } = requestOptions;
|
|
45
|
-
try {
|
|
46
|
-
return await super.onCtxRequest(requestOptions);
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
this.throwError(error, $ctx);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
throwError(error, $ctx) {
|
|
53
|
-
$ctx.getApp().emit("error", error, $ctx.getRequest().ctx);
|
|
25
|
+
return !$ctx.handlerMetadata.isFinal() && next();
|
|
54
26
|
}
|
|
55
27
|
}
|
|
56
28
|
//# sourceMappingURL=PlatformKoaHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,
|
|
1
|
+
{"version":3,"file":"PlatformKoaHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaHand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PlatformHandler, PlatformParamsCallback} from \"@tsed/common\";\nimport {isStream} from \"@tsed/core\";\nimport {PlatformContextHandler} from \"@tsed/platform-router\";\nimport \"./PlatformKoaRequest\";\n\nexport class PlatformKoaHandler extends PlatformHandler {\n public async flush($ctx: PlatformContext) {\n if ($ctx.data === undefined && $ctx.getResponse().body) {\n $ctx.data = $ctx.getResponse().body;\n }\n\n return super.flush($ctx);\n }\n\n async onRequest(handler: PlatformParamsCallback, $ctx: PlatformContext): Promise<any> {\n if ($ctx.error instanceof Error && !$ctx.handlerMetadata.hasErrorParam) {\n return;\n }\n\n return super.onRequest(handler, $ctx);\n }\n\n public next(error: unknown, next: any, $ctx: PlatformContext) {\n if (isStream($ctx.data) || $ctx.isDone()) {\n return;\n }\n\n if (error && !($ctx.handlerMetadata.isEndpoint() && !$ctx.handlerMetadata.isFinal())) {\n $ctx.getApp().emit(\"error\", error, $ctx.getRequest().ctx);\n return;\n }\n\n return !$ctx.handlerMetadata.isFinal() && next();\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AACrB,OAAO,EAAkB,eAAe,EAAC,MAAM,cAAc,CAAC;AAgB9D;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,eAA4B;IAClE,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AACrB,OAAO,EAAkB,eAAe,EAAC,MAAM,cAAc,CAAC;AAgB9D;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,eAA4B;IAClE,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAyB,CAAC;IACnD,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;IACnC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;IAC/B,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC;IACjC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;IAC7C,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;IAC1B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import \"@koa/router\";\nimport {PlatformContext, PlatformRequest} from \"@tsed/common\";\nimport Koa from \"koa\";\n\ndeclare module \"koa\" {\n export interface Request {\n id: string;\n $ctx: PlatformContext;\n }\n}\n\ndeclare global {\n namespace TsED {\n export interface Request extends Koa.Request {}\n }\n}\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoaRequest extends PlatformRequest<Koa.Request> {\n get ctx(): Koa.Context {\n return this.$ctx.event.koaContext as Koa.Context;\n }\n\n get protocol(): string {\n return this.ctx.request.protocol;\n }\n\n get host(): string {\n return this.ctx.request.host;\n }\n\n get secure(): boolean {\n return this.ctx.request.secure;\n }\n\n get cookies(): {[p: string]: any} {\n return this.ctx.cookie || this.ctx.cookies;\n }\n\n get session(): any {\n return this.ctx.session;\n }\n\n getReq() {\n return this.ctx.request.req;\n }\n}\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="koa__router" />
|
|
2
|
-
import
|
|
2
|
+
import { RouterOptions as KoaRouterOptions } from "@koa/router";
|
|
3
3
|
import { InjectorService, PlatformAdapter, PlatformBuilder, PlatformHandler, PlatformMulter, PlatformMulterSettings, PlatformRequest, PlatformResponse, PlatformStaticsOptions } from "@tsed/common";
|
|
4
4
|
import { Type } from "@tsed/core";
|
|
5
|
+
import { PlatformHandlerMetadata, PlatformLayer } from "@tsed/platform-router";
|
|
5
6
|
import Koa from "koa";
|
|
6
7
|
import send from "koa-send";
|
|
7
8
|
import { PlatformKoaHandler } from "../services/PlatformKoaHandler";
|
|
@@ -13,8 +14,6 @@ declare global {
|
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
namespace TsED {
|
|
16
|
-
interface Router extends KoaRouter {
|
|
17
|
-
}
|
|
18
17
|
interface RouterOptions extends KoaRouterOptions {
|
|
19
18
|
}
|
|
20
19
|
interface StaticsOptions extends send.SendOptions {
|
|
@@ -25,7 +24,7 @@ declare global {
|
|
|
25
24
|
* @platform
|
|
26
25
|
* @koa
|
|
27
26
|
*/
|
|
28
|
-
export declare class PlatformKoa implements PlatformAdapter<Koa
|
|
27
|
+
export declare class PlatformKoa implements PlatformAdapter<Koa> {
|
|
29
28
|
private injector;
|
|
30
29
|
readonly providers: ({
|
|
31
30
|
provide: typeof PlatformResponse;
|
|
@@ -43,25 +42,24 @@ export declare class PlatformKoa implements PlatformAdapter<Koa, KoaRouter> {
|
|
|
43
42
|
* @param module
|
|
44
43
|
* @param settings
|
|
45
44
|
*/
|
|
46
|
-
static create(module: Type<any>, settings?: Partial<TsED.Configuration>): PlatformBuilder<Koa<Koa.DefaultState, Koa.DefaultContext
|
|
45
|
+
static create(module: Type<any>, settings?: Partial<TsED.Configuration>): PlatformBuilder<Koa<Koa.DefaultState, Koa.DefaultContext>>;
|
|
47
46
|
/**
|
|
48
47
|
* Bootstrap a server application
|
|
49
48
|
* @param module
|
|
50
49
|
* @param settings
|
|
51
50
|
*/
|
|
52
|
-
static bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<PlatformBuilder<Koa<Koa.DefaultState, Koa.DefaultContext
|
|
51
|
+
static bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<PlatformBuilder<Koa<Koa.DefaultState, Koa.DefaultContext>>>;
|
|
53
52
|
onInit(): void;
|
|
54
|
-
|
|
53
|
+
beforeLoadRoutes(): Promise<void>;
|
|
54
|
+
mapLayers(layers: PlatformLayer[]): void;
|
|
55
|
+
mapHandler(handler: Function, metadata: PlatformHandlerMetadata): Function;
|
|
55
56
|
useContext(): this;
|
|
56
57
|
app(): {
|
|
57
58
|
app: any;
|
|
58
59
|
callback(): any;
|
|
59
60
|
};
|
|
60
|
-
router(routerOptions?: any): {
|
|
61
|
-
router: any;
|
|
62
|
-
callback(): any[];
|
|
63
|
-
};
|
|
64
61
|
multipart(options: PlatformMulterSettings): PlatformMulter;
|
|
65
62
|
statics(endpoint: string, options: PlatformStaticsOptions): any;
|
|
66
63
|
bodyParser(type: "json" | "urlencoded" | "raw" | "text", additionalOptions?: any): any;
|
|
64
|
+
private getPlatformApplication;
|
|
67
65
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export * from "./exports";
|
|
5
5
|
export * from "./components/PlatformKoa";
|
|
6
|
-
export * from "./decorators/caseSensitive";
|
|
7
6
|
export * from "./decorators/ctx";
|
|
8
|
-
export * from "./decorators/routerSettings";
|
|
9
7
|
export * from "./decorators/state";
|
|
10
|
-
export * from "./decorators/strict";
|
|
11
8
|
export * from "./interfaces/PlatformKoaSettings";
|
|
12
9
|
export * from "./interfaces/interfaces";
|
|
13
10
|
export * from "./middlewares/resourceNotFoundMiddleware";
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PlatformContext, PlatformHandler, PlatformParamsCallback } from "@tsed/common";
|
|
2
2
|
import "./PlatformKoaRequest";
|
|
3
3
|
export declare class PlatformKoaHandler extends PlatformHandler {
|
|
4
|
-
flush(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
protected onError(error: unknown, requestOptions: OnRequestOptions): any;
|
|
8
|
-
protected onCtxRequest(requestOptions: OnRequestOptions): Promise<any>;
|
|
9
|
-
protected throwError(error: any, $ctx: PlatformContext): void;
|
|
4
|
+
flush($ctx: PlatformContext): Promise<import("@tsed/common").PlatformResponse<any>>;
|
|
5
|
+
onRequest(handler: PlatformParamsCallback, $ctx: PlatformContext): Promise<any>;
|
|
6
|
+
next(error: unknown, next: any, $ctx: PlatformContext): any;
|
|
10
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-koa",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.14",
|
|
4
4
|
"description": "Koa package for Ts.ED framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"repository": "https://github.com/tsedio/tsed",
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@koa/cors": "3.3.0",
|
|
55
|
-
"@tsed/common": "7.0.0-beta.
|
|
56
|
-
"@tsed/core": "7.0.0-beta.
|
|
57
|
-
"@tsed/di": "7.0.0-beta.
|
|
58
|
-
"@tsed/platform-test-utils": "7.0.0-beta.
|
|
55
|
+
"@tsed/common": "7.0.0-beta.14",
|
|
56
|
+
"@tsed/core": "7.0.0-beta.14",
|
|
57
|
+
"@tsed/di": "7.0.0-beta.14",
|
|
58
|
+
"@tsed/platform-test-utils": "7.0.0-beta.14",
|
|
59
59
|
"@types/koa": "2.13.4",
|
|
60
60
|
"@types/koa-bodyparser": "4.3.7",
|
|
61
61
|
"@types/koa-compose": "3.2.5",
|
|
@@ -80,13 +80,13 @@
|
|
|
80
80
|
"tslib": "2.4.0"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
|
-
"@tsed/common": "^7.0.0-beta.
|
|
84
|
-
"@tsed/core": "^7.0.0-beta.
|
|
85
|
-
"@tsed/di": "^7.0.0-beta.
|
|
86
|
-
"@tsed/json-mapper": "^7.0.0-beta.
|
|
83
|
+
"@tsed/common": "^7.0.0-beta.14",
|
|
84
|
+
"@tsed/core": "^7.0.0-beta.14",
|
|
85
|
+
"@tsed/di": "^7.0.0-beta.14",
|
|
86
|
+
"@tsed/json-mapper": "^7.0.0-beta.14",
|
|
87
87
|
"@tsed/logger": ">=6.2.0",
|
|
88
|
-
"@tsed/openspec": "^7.0.0-beta.
|
|
89
|
-
"@tsed/schema": "^7.0.0-beta.
|
|
88
|
+
"@tsed/openspec": "^7.0.0-beta.14",
|
|
89
|
+
"@tsed/schema": "^7.0.0-beta.14",
|
|
90
90
|
"koa": ">=2.13.0",
|
|
91
91
|
"koa-bodyparser": ">=4.3.0",
|
|
92
92
|
"koa-compress": ">=5.0.1",
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CaseSensitive = void 0;
|
|
4
|
-
const routerSettings_1 = require("./routerSettings");
|
|
5
|
-
/**
|
|
6
|
-
* Specify the behavior of the router controller.
|
|
7
|
-
*
|
|
8
|
-
* ```typescript
|
|
9
|
-
* @Controller("/")
|
|
10
|
-
* @CaseSensitive(true)
|
|
11
|
-
* class MyCtrl {
|
|
12
|
-
*
|
|
13
|
-
* }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* Property | Description | Default
|
|
17
|
-
* ---|---|---
|
|
18
|
-
* CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
|
|
19
|
-
* Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
|
|
20
|
-
*
|
|
21
|
-
* @returns {Function}
|
|
22
|
-
* @decorator
|
|
23
|
-
* @koa
|
|
24
|
-
* @param sensitive
|
|
25
|
-
*/
|
|
26
|
-
function CaseSensitive(sensitive) {
|
|
27
|
-
return (0, routerSettings_1.RouterSettings)({ sensitive });
|
|
28
|
-
}
|
|
29
|
-
exports.CaseSensitive = CaseSensitive;
|
|
30
|
-
//# sourceMappingURL=caseSensitive.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"caseSensitive.js","sourceRoot":"","sources":["../../../src/decorators/caseSensitive.ts"],"names":[],"mappings":";;;AAAA,qDAAgD;AAEhD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,aAAa,CAAC,SAAkB;IAC9C,OAAO,IAAA,+BAAc,EAAC,EAAC,SAAS,EAAC,CAAC,CAAC;AACrC,CAAC;AAFD,sCAEC","sourcesContent":["import {RouterSettings} from \"./routerSettings\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @CaseSensitive(true)\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @returns {Function}\n * @decorator\n * @koa\n * @param sensitive\n */\nexport function CaseSensitive(sensitive: boolean) {\n return RouterSettings({sensitive});\n}\n"]}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RouterSettings = void 0;
|
|
4
|
-
const common_1 = require("@tsed/common");
|
|
5
|
-
const core_1 = require("@tsed/core");
|
|
6
|
-
/**
|
|
7
|
-
* Specify the behavior of the router controller.
|
|
8
|
-
*
|
|
9
|
-
* ```typescript
|
|
10
|
-
* @Controller("/")
|
|
11
|
-
* @RouterSettings({sensitive: true})
|
|
12
|
-
* class MyCtrl {
|
|
13
|
-
*
|
|
14
|
-
* }
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* Property | Description | Default
|
|
18
|
-
* ---|---|---
|
|
19
|
-
* sensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
|
|
20
|
-
* strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
|
|
21
|
-
*
|
|
22
|
-
* @returns {(target:any)=>void}
|
|
23
|
-
* @decorator
|
|
24
|
-
* @param routerOptions
|
|
25
|
-
* @koa
|
|
26
|
-
*/
|
|
27
|
-
function RouterSettings(routerOptions) {
|
|
28
|
-
return (0, core_1.StoreMerge)(common_1.ROUTER_OPTIONS, routerOptions);
|
|
29
|
-
}
|
|
30
|
-
exports.RouterSettings = RouterSettings;
|
|
31
|
-
//# sourceMappingURL=routerSettings.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routerSettings.js","sourceRoot":"","sources":["../../../src/decorators/routerSettings.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,qCAAsC;AAGtC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,cAAc,CAAC,aAA4B;IACzD,OAAO,IAAA,iBAAU,EAAC,uBAAc,EAAE,aAAa,CAAC,CAAC;AACnD,CAAC;AAFD,wCAEC","sourcesContent":["import {ROUTER_OPTIONS} from \"@tsed/common\";\nimport {StoreMerge} from \"@tsed/core\";\nimport {RouterOptions} from \"@koa/router\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @RouterSettings({sensitive: true})\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * sensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @returns {(target:any)=>void}\n * @decorator\n * @param routerOptions\n * @koa\n */\nexport function RouterSettings(routerOptions: RouterOptions): Function {\n return StoreMerge(ROUTER_OPTIONS, routerOptions);\n}\n"]}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Strict = void 0;
|
|
4
|
-
const routerSettings_1 = require("./routerSettings");
|
|
5
|
-
/**
|
|
6
|
-
* Specify the behavior of the router controller.
|
|
7
|
-
*
|
|
8
|
-
* ```typescript
|
|
9
|
-
* @Controller("/")
|
|
10
|
-
* @Strict(true)
|
|
11
|
-
* class MyCtrl {
|
|
12
|
-
*
|
|
13
|
-
* }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* Property | Description | Default
|
|
17
|
-
* ---|---|---
|
|
18
|
-
* CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
|
|
19
|
-
* MergeParams | Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. | false
|
|
20
|
-
* Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
|
|
21
|
-
*
|
|
22
|
-
* @param strict
|
|
23
|
-
* @returns {Function}
|
|
24
|
-
* @decorator
|
|
25
|
-
* @koa
|
|
26
|
-
*/
|
|
27
|
-
function Strict(strict) {
|
|
28
|
-
return (0, routerSettings_1.RouterSettings)({ strict });
|
|
29
|
-
}
|
|
30
|
-
exports.Strict = Strict;
|
|
31
|
-
//# sourceMappingURL=strict.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"strict.js","sourceRoot":"","sources":["../../../src/decorators/strict.ts"],"names":[],"mappings":";;;AAAA,qDAAgD;AAEhD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,MAAM,CAAC,MAAe;IACpC,OAAO,IAAA,+BAAc,EAAC,EAAC,MAAM,EAAC,CAAC,CAAC;AAClC,CAAC;AAFD,wBAEC","sourcesContent":["import {RouterSettings} from \"./routerSettings\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @Strict(true)\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * MergeParams | Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. | false\n * Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @param strict\n * @returns {Function}\n * @decorator\n * @koa\n */\nexport function Strict(strict: boolean) {\n return RouterSettings({strict});\n}\n"]}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { RouterSettings } from "./routerSettings.js";
|
|
2
|
-
/**
|
|
3
|
-
* Specify the behavior of the router controller.
|
|
4
|
-
*
|
|
5
|
-
* ```typescript
|
|
6
|
-
* @Controller("/")
|
|
7
|
-
* @CaseSensitive(true)
|
|
8
|
-
* class MyCtrl {
|
|
9
|
-
*
|
|
10
|
-
* }
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* Property | Description | Default
|
|
14
|
-
* ---|---|---
|
|
15
|
-
* CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
|
|
16
|
-
* Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
|
|
17
|
-
*
|
|
18
|
-
* @returns {Function}
|
|
19
|
-
* @decorator
|
|
20
|
-
* @koa
|
|
21
|
-
* @param sensitive
|
|
22
|
-
*/
|
|
23
|
-
export function CaseSensitive(sensitive) {
|
|
24
|
-
return RouterSettings({ sensitive });
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=caseSensitive.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"caseSensitive.js","sourceRoot":"","sources":["../../../src/decorators/caseSensitive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,aAAa,CAAC,SAAkB;IAC9C,OAAO,cAAc,CAAC,EAAC,SAAS,EAAC,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import {RouterSettings} from \"./routerSettings\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @CaseSensitive(true)\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @returns {Function}\n * @decorator\n * @koa\n * @param sensitive\n */\nexport function CaseSensitive(sensitive: boolean) {\n return RouterSettings({sensitive});\n}\n"]}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ROUTER_OPTIONS } from "@tsed/common";
|
|
2
|
-
import { StoreMerge } from "@tsed/core";
|
|
3
|
-
/**
|
|
4
|
-
* Specify the behavior of the router controller.
|
|
5
|
-
*
|
|
6
|
-
* ```typescript
|
|
7
|
-
* @Controller("/")
|
|
8
|
-
* @RouterSettings({sensitive: true})
|
|
9
|
-
* class MyCtrl {
|
|
10
|
-
*
|
|
11
|
-
* }
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* Property | Description | Default
|
|
15
|
-
* ---|---|---
|
|
16
|
-
* sensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
|
|
17
|
-
* strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
|
|
18
|
-
*
|
|
19
|
-
* @returns {(target:any)=>void}
|
|
20
|
-
* @decorator
|
|
21
|
-
* @param routerOptions
|
|
22
|
-
* @koa
|
|
23
|
-
*/
|
|
24
|
-
export function RouterSettings(routerOptions) {
|
|
25
|
-
return StoreMerge(ROUTER_OPTIONS, routerOptions);
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=routerSettings.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routerSettings.js","sourceRoot":"","sources":["../../../src/decorators/routerSettings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AAGtC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,cAAc,CAAC,aAA4B;IACzD,OAAO,UAAU,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import {ROUTER_OPTIONS} from \"@tsed/common\";\nimport {StoreMerge} from \"@tsed/core\";\nimport {RouterOptions} from \"@koa/router\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @RouterSettings({sensitive: true})\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * sensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @returns {(target:any)=>void}\n * @decorator\n * @param routerOptions\n * @koa\n */\nexport function RouterSettings(routerOptions: RouterOptions): Function {\n return StoreMerge(ROUTER_OPTIONS, routerOptions);\n}\n"]}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { RouterSettings } from "./routerSettings.js";
|
|
2
|
-
/**
|
|
3
|
-
* Specify the behavior of the router controller.
|
|
4
|
-
*
|
|
5
|
-
* ```typescript
|
|
6
|
-
* @Controller("/")
|
|
7
|
-
* @Strict(true)
|
|
8
|
-
* class MyCtrl {
|
|
9
|
-
*
|
|
10
|
-
* }
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* Property | Description | Default
|
|
14
|
-
* ---|---|---
|
|
15
|
-
* CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
|
|
16
|
-
* MergeParams | Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. | false
|
|
17
|
-
* Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
|
|
18
|
-
*
|
|
19
|
-
* @param strict
|
|
20
|
-
* @returns {Function}
|
|
21
|
-
* @decorator
|
|
22
|
-
* @koa
|
|
23
|
-
*/
|
|
24
|
-
export function Strict(strict) {
|
|
25
|
-
return RouterSettings({ strict });
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=strict.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"strict.js","sourceRoot":"","sources":["../../../src/decorators/strict.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,MAAM,CAAC,MAAe;IACpC,OAAO,cAAc,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC;AAClC,CAAC","sourcesContent":["import {RouterSettings} from \"./routerSettings\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @Strict(true)\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * MergeParams | Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. | false\n * Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @param strict\n * @returns {Function}\n * @decorator\n * @koa\n */\nexport function Strict(strict: boolean) {\n return RouterSettings({strict});\n}\n"]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Specify the behavior of the router controller.
|
|
3
|
-
*
|
|
4
|
-
* ```typescript
|
|
5
|
-
* @Controller("/")
|
|
6
|
-
* @CaseSensitive(true)
|
|
7
|
-
* class MyCtrl {
|
|
8
|
-
*
|
|
9
|
-
* }
|
|
10
|
-
* ```
|
|
11
|
-
*
|
|
12
|
-
* Property | Description | Default
|
|
13
|
-
* ---|---|---
|
|
14
|
-
* CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
|
|
15
|
-
* Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
|
|
16
|
-
*
|
|
17
|
-
* @returns {Function}
|
|
18
|
-
* @decorator
|
|
19
|
-
* @koa
|
|
20
|
-
* @param sensitive
|
|
21
|
-
*/
|
|
22
|
-
export declare function CaseSensitive(sensitive: boolean): Function;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/// <reference types="koa__router" />
|
|
2
|
-
import { RouterOptions } from "@koa/router";
|
|
3
|
-
/**
|
|
4
|
-
* Specify the behavior of the router controller.
|
|
5
|
-
*
|
|
6
|
-
* ```typescript
|
|
7
|
-
* @Controller("/")
|
|
8
|
-
* @RouterSettings({sensitive: true})
|
|
9
|
-
* class MyCtrl {
|
|
10
|
-
*
|
|
11
|
-
* }
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* Property | Description | Default
|
|
15
|
-
* ---|---|---
|
|
16
|
-
* sensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
|
|
17
|
-
* strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
|
|
18
|
-
*
|
|
19
|
-
* @returns {(target:any)=>void}
|
|
20
|
-
* @decorator
|
|
21
|
-
* @param routerOptions
|
|
22
|
-
* @koa
|
|
23
|
-
*/
|
|
24
|
-
export declare function RouterSettings(routerOptions: RouterOptions): Function;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Specify the behavior of the router controller.
|
|
3
|
-
*
|
|
4
|
-
* ```typescript
|
|
5
|
-
* @Controller("/")
|
|
6
|
-
* @Strict(true)
|
|
7
|
-
* class MyCtrl {
|
|
8
|
-
*
|
|
9
|
-
* }
|
|
10
|
-
* ```
|
|
11
|
-
*
|
|
12
|
-
* Property | Description | Default
|
|
13
|
-
* ---|---|---
|
|
14
|
-
* CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
|
|
15
|
-
* MergeParams | Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. | false
|
|
16
|
-
* Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
|
|
17
|
-
*
|
|
18
|
-
* @param strict
|
|
19
|
-
* @returns {Function}
|
|
20
|
-
* @decorator
|
|
21
|
-
* @koa
|
|
22
|
-
*/
|
|
23
|
-
export declare function Strict(strict: boolean): Function;
|