@tsed/platform-koa 6.70.1 → 7.0.0-alpha.1
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/lib/components/PlatformKoa.d.ts +0 -2
- package/lib/components/PlatformKoa.js +6 -9
- package/lib/components/PlatformKoa.js.map +1 -1
- package/lib/decorators/ctx.js +1 -1
- package/lib/decorators/ctx.js.map +1 -1
- package/lib/services/PlatformKoaRequest.d.ts +4 -1
- package/lib/services/PlatformKoaRequest.js +18 -5
- package/lib/services/PlatformKoaRequest.js.map +1 -1
- package/lib/services/PlatformKoaResponse.d.ts +3 -1
- package/lib/services/PlatformKoaResponse.js +14 -6
- package/lib/services/PlatformKoaResponse.js.map +1 -1
- package/package.json +12 -12
|
@@ -26,8 +26,6 @@ export declare class PlatformKoa extends PlatformBuilder<Koa, KoaRouter> {
|
|
|
26
26
|
useClass: typeof PlatformKoaApplication;
|
|
27
27
|
})[];
|
|
28
28
|
static bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<PlatformKoa>;
|
|
29
|
-
createRequest(req: any): PlatformKoaRequest;
|
|
30
|
-
createResponse(res: any): PlatformKoaResponse;
|
|
31
29
|
protected createInjector(module: Type<any>, settings: any): void;
|
|
32
30
|
protected useRouter(): this;
|
|
33
31
|
protected useContext(): this;
|
|
@@ -12,14 +12,6 @@ class PlatformKoa extends common_1.PlatformBuilder {
|
|
|
12
12
|
static async bootstrap(module, settings = {}) {
|
|
13
13
|
return this.build(PlatformKoa).bootstrap(module, settings);
|
|
14
14
|
}
|
|
15
|
-
createRequest(req) {
|
|
16
|
-
return new services_1.PlatformKoaRequest(req);
|
|
17
|
-
}
|
|
18
|
-
createResponse(res) {
|
|
19
|
-
const response = new services_1.PlatformKoaResponse(res);
|
|
20
|
-
response.platformViews = this.injector.get(common_1.PlatformViews);
|
|
21
|
-
return response;
|
|
22
|
-
}
|
|
23
15
|
createInjector(module, settings) {
|
|
24
16
|
super.createInjector(module, settings);
|
|
25
17
|
const listener = (error, ctx) => {
|
|
@@ -35,8 +27,13 @@ class PlatformKoa extends common_1.PlatformBuilder {
|
|
|
35
27
|
}
|
|
36
28
|
useContext() {
|
|
37
29
|
this.logger.info("Mount app context");
|
|
30
|
+
const invoke = common_1.createContext(this.injector);
|
|
38
31
|
this.app.getApp().use(async (ctx, next) => {
|
|
39
|
-
await
|
|
32
|
+
await invoke({
|
|
33
|
+
request: ctx.request,
|
|
34
|
+
response: ctx.response,
|
|
35
|
+
ctx
|
|
36
|
+
});
|
|
40
37
|
return next();
|
|
41
38
|
});
|
|
42
39
|
return this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../src/components/PlatformKoa.ts"],"names":[],"mappings":";;;AACA,yCAUsB;AAGtB,0FAAqF;AACrF,0CAAmI;AAEnI;;;GAGG;AACH,MAAa,WAAY,SAAQ,wBAA+B;IAwB9D,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,MAAiB,EAAE,WAAwC,EAAE;QAClF,OAAO,IAAI,CAAC,KAAK,CAAc,WAAW,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC1E,CAAC;
|
|
1
|
+
{"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../src/components/PlatformKoa.ts"],"names":[],"mappings":";;;AACA,yCAUsB;AAGtB,0FAAqF;AACrF,0CAAmI;AAEnI;;;GAGG;AACH,MAAa,WAAY,SAAQ,wBAA+B;IAwB9D,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,MAAiB,EAAE,WAAwC,EAAE;QAClF,OAAO,IAAI,CAAC,KAAK,CAAc,WAAW,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC1E,CAAC;IAES,cAAc,CAAC,MAAiB,EAAE,QAAa;QACvD,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAEvC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AE,8BAAmB;KAC9B;IACD;QACE,OAAO,EAAE,wBAAe;QACxB,QAAQ,EAAE,6BAAkB;KAC7B;IACD;QACE,OAAO,EAAE,wBAAe;QACxB,QAAQ,EAAE,6BAAkB;KAC7B;IACD;QACE,OAAO,EAAE,uBAAc;QACvB,QAAQ,EAAE,4BAAiB;KAC5B;IACD;QACE,OAAO,EAAE,4BAAmB;QAC5B,QAAQ,EAAE,iCAAsB;KACjC;CACF,CAAC","sourcesContent":["import KoaRouter from \"@koa/router\";\nimport {\n createContext,\n PlatformApplication,\n PlatformBuilder,\n PlatformExceptions,\n PlatformHandler,\n PlatformRequest,\n PlatformResponse,\n PlatformRouter,\n PlatformViews\n} from \"@tsed/common\";\nimport {Type} from \"@tsed/core\";\nimport Koa, {Context, Next} from \"koa\";\nimport {resourceNotFoundMiddleware} from \"../middlewares/resourceNotFoundMiddleware\";\nimport {PlatformKoaApplication, PlatformKoaHandler, PlatformKoaRequest, PlatformKoaResponse, PlatformKoaRouter} from \"../services\";\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoa extends PlatformBuilder<Koa, KoaRouter> {\n static 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 provide: PlatformRouter,\n useClass: PlatformKoaRouter\n },\n {\n provide: PlatformApplication,\n useClass: PlatformKoaApplication\n }\n ];\n\n static async bootstrap(module: Type<any>, settings: Partial<TsED.Configuration> = {}): Promise<PlatformKoa> {\n return this.build<PlatformKoa>(PlatformKoa).bootstrap(module, settings);\n }\n\n protected createInjector(module: Type<any>, settings: any) {\n super.createInjector(module, settings);\n\n const listener: any = (error: any, ctx: Koa.Context) => {\n this.injector.get<PlatformExceptions>(PlatformExceptions)?.catch(error, ctx.request.$ctx);\n };\n\n this.app.getApp().silent = true;\n this.app.getApp().on(\"error\", listener);\n }\n\n protected useRouter(): this {\n this.app.getApp().use(resourceNotFoundMiddleware).use(this.app.getRouter().routes()).use(this.app.getRouter().allowedMethods());\n\n return this;\n }\n\n protected useContext(): this {\n this.logger.info(\"Mount app context\");\n\n const invoke = createContext(this.injector);\n\n this.app.getApp().use(async (ctx: Context, next: Next) => {\n await invoke({\n request: ctx.request as any,\n response: ctx.response as any,\n ctx\n });\n\n return next();\n });\n\n return this;\n }\n}\n"]}
|
package/lib/decorators/ctx.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ctx.js","sourceRoot":"","sources":["../../src/decorators/ctx.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAGtC;;;;;;GAMG;AACH,SAAgB,MAAM;IACpB,OAAO,iBAAQ,CAAC
|
|
1
|
+
{"version":3,"file":"ctx.js","sourceRoot":"","sources":["../../src/decorators/ctx.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAGtC;;;;;;GAMG;AACH,SAAgB,MAAM;IACpB,OAAO,iBAAQ,CAAC;QACd,SAAS,EAAE,SAAS;QACpB,QAAQ,EAAE,kBAAkB;QAC5B,YAAY,EAAE,KAAK;QACnB,aAAa,EAAE,KAAK;KACrB,CAAC,CAAC;AACL,CAAC;AAPD,wBAOC;AAED;;;;;;GAMG;AACH,SAAgB,GAAG;IACjB,OAAO,MAAM,EAAE,CAAC;AAClB,CAAC;AAFD,kBAEC","sourcesContent":["import {UseParam} from \"@tsed/common\";\nimport type {Context} from \"koa\";\n\n/**\n * Return the original Koa context.\n * @decorator\n * @operation\n * @input\n * @koa\n */\nexport function KoaCtx(): ParameterDecorator {\n return UseParam({\n paramType: \"KOA_CTX\",\n dataPath: \"$ctx.request.ctx\",\n useConverter: false,\n useValidation: false\n });\n}\n\n/**\n * Return the original Koa context.\n * @decorator\n * @operation\n * @input\n * @koa\n */\nexport function Ctx(): ParameterDecorator {\n return KoaCtx();\n}\n\nexport type Ctx = Context;\nexport type KoaCtx = Context;\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import "@koa/router";
|
|
3
|
-
import { PlatformContext, PlatformRequest } from "@tsed/common";
|
|
3
|
+
import { IncomingEvent, PlatformContext, PlatformRequest } from "@tsed/common";
|
|
4
4
|
import { IncomingMessage } from "http";
|
|
5
5
|
import Koa from "koa";
|
|
6
6
|
declare module "koa" {
|
|
@@ -20,6 +20,8 @@ declare global {
|
|
|
20
20
|
* @koa
|
|
21
21
|
*/
|
|
22
22
|
export declare class PlatformKoaRequest extends PlatformRequest<Koa.Request> {
|
|
23
|
+
#private;
|
|
24
|
+
constructor(event: IncomingEvent);
|
|
23
25
|
get protocol(): string;
|
|
24
26
|
get host(): string;
|
|
25
27
|
get secure(): boolean;
|
|
@@ -28,4 +30,5 @@ export declare class PlatformKoaRequest extends PlatformRequest<Koa.Request> {
|
|
|
28
30
|
};
|
|
29
31
|
get session(): any;
|
|
30
32
|
getReq(): IncomingMessage;
|
|
33
|
+
destroy(): void;
|
|
31
34
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _ctx;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.PlatformKoaRequest = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
4
6
|
require("@koa/router");
|
|
5
7
|
const common_1 = require("@tsed/common");
|
|
6
8
|
/**
|
|
@@ -8,24 +10,35 @@ const common_1 = require("@tsed/common");
|
|
|
8
10
|
* @koa
|
|
9
11
|
*/
|
|
10
12
|
class PlatformKoaRequest extends common_1.PlatformRequest {
|
|
13
|
+
constructor(event) {
|
|
14
|
+
super(event);
|
|
15
|
+
_ctx.set(this, void 0);
|
|
16
|
+
tslib_1.__classPrivateFieldSet(this, _ctx, this.raw.ctx);
|
|
17
|
+
}
|
|
11
18
|
get protocol() {
|
|
12
|
-
return this.
|
|
19
|
+
return tslib_1.__classPrivateFieldGet(this, _ctx).request.protocol;
|
|
13
20
|
}
|
|
14
21
|
get host() {
|
|
15
|
-
return this.
|
|
22
|
+
return tslib_1.__classPrivateFieldGet(this, _ctx).request.host;
|
|
16
23
|
}
|
|
17
24
|
get secure() {
|
|
18
|
-
return this.
|
|
25
|
+
return tslib_1.__classPrivateFieldGet(this, _ctx).request.secure;
|
|
19
26
|
}
|
|
20
27
|
get cookies() {
|
|
21
|
-
return this.
|
|
28
|
+
return tslib_1.__classPrivateFieldGet(this, _ctx).cookie || tslib_1.__classPrivateFieldGet(this, _ctx).cookies;
|
|
22
29
|
}
|
|
23
30
|
get session() {
|
|
24
|
-
return this.
|
|
31
|
+
return tslib_1.__classPrivateFieldGet(this, _ctx).session;
|
|
25
32
|
}
|
|
26
33
|
getReq() {
|
|
27
34
|
return this.raw.req;
|
|
28
35
|
}
|
|
36
|
+
destroy() {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
tslib_1.__classPrivateFieldSet(this, _ctx, null);
|
|
39
|
+
return super.destroy();
|
|
40
|
+
}
|
|
29
41
|
}
|
|
30
42
|
exports.PlatformKoaRequest = PlatformKoaRequest;
|
|
43
|
+
_ctx = new WeakMap();
|
|
31
44
|
//# sourceMappingURL=PlatformKoaRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":";;;;;AAAA,uBAAqB;AACrB,yCAA6E;AAiB7E;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,wBAA4B;IAGlE,YAAY,KAAoB;QAC9B,KAAK,CAAC,KAAK,CAAC,CAAC;QAHf,uBAAkB;QAIhB,+BAAA,IAAI,QAAQ,IAAI,CAAC,GAAG,CAAC,GAAG,EAAC;IAC3B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,2CAAU,OAAO,CAAC,QAAQ,CAAC;IACpC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,2CAAU,OAAO,CAAC,IAAI,CAAC;IAChC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,2CAAU,OAAO,CAAC,MAAM,CAAC;IAClC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,2CAAU,MAAM,IAAI,2CAAU,OAAO,CAAC;IAC/C,CAAC;IAED,IAAI,OAAO;QACT,OAAO,2CAAU,OAAO,CAAC;IAC3B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACtB,CAAC;IAED,OAAO;QACL,aAAa;QACb,+BAAA,IAAI,QAAQ,IAAI,EAAC;QACjB,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF;AArCD,gDAqCC","sourcesContent":["import \"@koa/router\";\nimport {IncomingEvent, PlatformContext, PlatformRequest} from \"@tsed/common\";\nimport {IncomingMessage} from \"http\";\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 #ctx: Koa.Context;\n\n constructor(event: IncomingEvent) {\n super(event);\n this.#ctx = this.raw.ctx;\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(): IncomingMessage {\n return this.raw.req;\n }\n\n destroy() {\n // @ts-ignore\n this.#ctx = null;\n return super.destroy();\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { PlatformResponse } from "@tsed/common";
|
|
2
|
+
import { IncomingEvent, PlatformResponse } from "@tsed/common";
|
|
3
3
|
import { ServerResponse } from "http";
|
|
4
4
|
import Koa from "koa";
|
|
5
5
|
declare global {
|
|
@@ -13,6 +13,8 @@ declare global {
|
|
|
13
13
|
* @koa
|
|
14
14
|
*/
|
|
15
15
|
export declare class PlatformKoaResponse extends PlatformResponse<Koa.Response> {
|
|
16
|
+
#private;
|
|
17
|
+
constructor(event: IncomingEvent);
|
|
16
18
|
get statusCode(): number;
|
|
17
19
|
get locals(): Koa.DefaultState;
|
|
18
20
|
/**
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _ctx;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.PlatformKoaResponse = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
4
6
|
const common_1 = require("@tsed/common");
|
|
5
|
-
const
|
|
7
|
+
const schema_1 = require("@tsed/schema");
|
|
6
8
|
const encodeUrl = require("encodeurl");
|
|
7
9
|
/**
|
|
8
10
|
* @platform
|
|
9
11
|
* @koa
|
|
10
12
|
*/
|
|
11
13
|
class PlatformKoaResponse extends common_1.PlatformResponse {
|
|
14
|
+
constructor(event) {
|
|
15
|
+
super(event);
|
|
16
|
+
_ctx.set(this, void 0);
|
|
17
|
+
tslib_1.__classPrivateFieldSet(this, _ctx, this.raw.ctx);
|
|
18
|
+
}
|
|
12
19
|
get statusCode() {
|
|
13
20
|
return this.raw.status;
|
|
14
21
|
}
|
|
15
22
|
get locals() {
|
|
16
|
-
return this.
|
|
23
|
+
return tslib_1.__classPrivateFieldGet(this, _ctx).state;
|
|
17
24
|
}
|
|
18
25
|
/**
|
|
19
26
|
* Return the Node.js response object
|
|
@@ -72,10 +79,10 @@ class PlatformKoaResponse extends common_1.PlatformResponse {
|
|
|
72
79
|
status = status || 302;
|
|
73
80
|
// Set location header
|
|
74
81
|
url = this.location(url).raw.get("Location");
|
|
75
|
-
this.body(`${
|
|
82
|
+
this.body(`${schema_1.getStatusMessage(status)}. Redirecting to ${url}`);
|
|
76
83
|
this.status(status);
|
|
77
84
|
this.setHeader("Content-Length", Buffer.byteLength(this.raw.body));
|
|
78
|
-
if (this.
|
|
85
|
+
if (this.request.method === "HEAD") {
|
|
79
86
|
this.getRes().end();
|
|
80
87
|
}
|
|
81
88
|
else {
|
|
@@ -86,12 +93,13 @@ class PlatformKoaResponse extends common_1.PlatformResponse {
|
|
|
86
93
|
location(location) {
|
|
87
94
|
// "back" is an alias for the referrer
|
|
88
95
|
if (location === "back") {
|
|
89
|
-
location = this.
|
|
96
|
+
location = this.request.get("Referrer") || "/";
|
|
90
97
|
}
|
|
91
98
|
// set location
|
|
92
|
-
this.
|
|
99
|
+
this.raw.set("Location", encodeUrl(location));
|
|
93
100
|
return this;
|
|
94
101
|
}
|
|
95
102
|
}
|
|
96
103
|
exports.PlatformKoaResponse = PlatformKoaResponse;
|
|
104
|
+
_ctx = new WeakMap();
|
|
97
105
|
//# sourceMappingURL=PlatformKoaResponse.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":";;;;;AAAA,yCAA6D;AAG7D,yCAA8C;AAE9C,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAQvC;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,yBAA8B;IAGrE,YAAY,KAAoB;QAC9B,KAAK,CAAC,KAAK,CAAC,CAAC;QAHf,uBAAkB;QAIhB,+BAAA,IAAI,QAAQ,IAAI,CAAC,GAAG,CAAC,GAAG,EAAC;IAC3B,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;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QAEnE,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE;YAClC,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC;SACrB;aAAM;YACL,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;SACnC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ,CAAC,QAAgB;QACvB,sCAAsC;QACtC,IAAI,QAAQ,KAAK,MAAM,EAAE;YACvB,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC;SAChD;QAED,eAAe;QACf,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;QAE9C,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA5GD,kDA4GC","sourcesContent":["import {IncomingEvent, PlatformResponse} from \"@tsed/common\";\nimport {ServerResponse} from \"http\";\nimport Koa from \"koa\";\nimport {getStatusMessage} from \"@tsed/schema\";\n\nconst encodeUrl = require(\"encodeurl\");\n\ndeclare global {\n namespace TsED {\n export interface Response extends Koa.Response {}\n }\n}\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoaResponse extends PlatformResponse<Koa.Response> {\n #ctx: Koa.Context;\n\n constructor(event: IncomingEvent) {\n super(event);\n this.#ctx = this.raw.ctx;\n }\n\n get statusCode() {\n return this.raw.status;\n }\n\n get locals() {\n return this.#ctx.state;\n }\n\n /**\n * Return the Node.js response object\n */\n getRes(): ServerResponse {\n return this.raw.res;\n }\n\n hasStatus() {\n // KOA set 404 by default\n return this.statusCode !== 404;\n }\n\n /**\n * Sets the HTTP status for the response.\n *\n * @param status\n */\n status(status: number) {\n this.raw.status = status;\n\n return this;\n }\n\n /**\n * Set `Content-Type` response header with `type` through `mime.lookup()`\n * when it does not contain \"/\", or set the Content-Type to `type` otherwise.\n *\n * Examples:\n *\n * res.type('.html');\n * res.type('html');\n * res.type('json');\n * res.type('application/json');\n * res.type('png');\n */\n contentType(contentType: string) {\n this.raw.type = contentType;\n\n return this;\n }\n\n getHeaders() {\n return this.raw.headers;\n }\n\n /**\n * Send any data to your consumer.\n *\n * This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.\n * It choose the better way to send the data.\n *\n * @param data\n */\n body(data: any): this {\n this.raw.body = data;\n\n return this;\n }\n\n getBody() {\n return this.raw.body;\n }\n\n redirect(status: number, url: string): this {\n status = status || 302;\n // Set location header\n url = this.location(url).raw.get(\"Location\");\n\n this.body(`${getStatusMessage(status)}. Redirecting to ${url}`);\n this.status(status);\n this.setHeader(\"Content-Length\", Buffer.byteLength(this.raw.body));\n\n if (this.request.method === \"HEAD\") {\n this.getRes().end();\n } else {\n this.getRes().end(this.getBody());\n }\n\n return this;\n }\n\n location(location: string): this {\n // \"back\" is an alias for the referrer\n if (location === \"back\") {\n location = this.request.get(\"Referrer\") || \"/\";\n }\n\n // set location\n this.raw.set(\"Location\", encodeUrl(location));\n\n return this;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-koa",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.1",
|
|
4
4
|
"description": "Koa package for Ts.ED framework",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"bugs": {
|
|
34
34
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
35
35
|
},
|
|
36
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
36
|
+
"homepage": "https://github.com/tsedio/tsed/tree/alpha/packages/platform/platform-koa",
|
|
37
37
|
"repository": "https://github.com/tsedio/tsed",
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsc --build tsconfig.compile.json",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@koa/cors": "3.1.0",
|
|
44
|
-
"@tsed/common": "
|
|
45
|
-
"@tsed/core": "
|
|
46
|
-
"@tsed/di": "
|
|
47
|
-
"@tsed/platform-test-utils": "
|
|
44
|
+
"@tsed/common": "7.0.0-alpha.1",
|
|
45
|
+
"@tsed/core": "7.0.0-alpha.1",
|
|
46
|
+
"@tsed/di": "7.0.0-alpha.1",
|
|
47
|
+
"@tsed/platform-test-utils": "7.0.0-alpha.1",
|
|
48
48
|
"@types/koa": "2.11.3",
|
|
49
49
|
"@types/koa-bodyparser": "4.3.0",
|
|
50
50
|
"@types/koa-compose": "3.2.5",
|
|
@@ -69,13 +69,13 @@
|
|
|
69
69
|
"tslib": "2.2.0"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
|
-
"@tsed/common": "^
|
|
73
|
-
"@tsed/core": "^
|
|
74
|
-
"@tsed/di": "^
|
|
75
|
-
"@tsed/json-mapper": "^
|
|
72
|
+
"@tsed/common": "^7.0.0-alpha.1",
|
|
73
|
+
"@tsed/core": "^7.0.0-alpha.1",
|
|
74
|
+
"@tsed/di": "^7.0.0-alpha.1",
|
|
75
|
+
"@tsed/json-mapper": "^7.0.0-alpha.1",
|
|
76
76
|
"@tsed/logger": "^5.16.0",
|
|
77
|
-
"@tsed/openspec": "^
|
|
78
|
-
"@tsed/schema": "^
|
|
77
|
+
"@tsed/openspec": "^7.0.0-alpha.1",
|
|
78
|
+
"@tsed/schema": "^7.0.0-alpha.1",
|
|
79
79
|
"koa": "2.13.0",
|
|
80
80
|
"koa-bodyparser": "4.3.0",
|
|
81
81
|
"koa-compress": "5.0.1",
|