@tsed/platform-koa 6.70.2 → 6.71.0
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.
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PlatformKoaResponse = void 0;
|
|
4
4
|
const common_1 = require("@tsed/common");
|
|
5
|
-
const
|
|
5
|
+
const schema_1 = require("@tsed/schema");
|
|
6
6
|
const encodeUrl = require("encodeurl");
|
|
7
7
|
/**
|
|
8
8
|
* @platform
|
|
@@ -72,7 +72,7 @@ class PlatformKoaResponse extends common_1.PlatformResponse {
|
|
|
72
72
|
status = status || 302;
|
|
73
73
|
// Set location header
|
|
74
74
|
url = this.location(url).raw.get("Location");
|
|
75
|
-
this.body(`${
|
|
75
|
+
this.body(`${schema_1.getStatusMessage(status)}. Redirecting to ${url}`);
|
|
76
76
|
this.status(status);
|
|
77
77
|
this.setHeader("Content-Length", Buffer.byteLength(this.raw.body));
|
|
78
78
|
if (this.raw.ctx.req.method === "HEAD") {
|
|
@@ -89,7 +89,7 @@ class PlatformKoaResponse extends common_1.PlatformResponse {
|
|
|
89
89
|
location = this.raw.ctx.get("Referrer") || "/";
|
|
90
90
|
}
|
|
91
91
|
// set location
|
|
92
|
-
this.
|
|
92
|
+
this.raw.set("Location", encodeUrl(location));
|
|
93
93
|
return this;
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":";;;AAAA,yCAA8C;
|
|
1
|
+
{"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":";;;AAAA,yCAA8C;AAG9C,yCAA8C;AAE9C,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAQvC;;;GAGG;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M,CAAC,CAAC;QACpB,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;QAEnE,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE;YACtC,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,GAAG,CAAC,GAAG,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;AApGD,kDAoGC","sourcesContent":["import {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 get statusCode() {\n return this.raw.status;\n }\n\n get locals() {\n return this.raw.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 * 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.raw.ctx.req.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.raw.ctx.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": "6.
|
|
3
|
+
"version": "6.71.0",
|
|
4
4
|
"description": "Koa package for Ts.ED framework",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@koa/cors": "3.1.0",
|
|
44
|
-
"@tsed/common": "6.
|
|
45
|
-
"@tsed/core": "6.
|
|
46
|
-
"@tsed/di": "6.
|
|
47
|
-
"@tsed/platform-test-utils": "6.
|
|
44
|
+
"@tsed/common": "6.71.0",
|
|
45
|
+
"@tsed/core": "6.71.0",
|
|
46
|
+
"@tsed/di": "6.71.0",
|
|
47
|
+
"@tsed/platform-test-utils": "6.71.0",
|
|
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": "^6.
|
|
73
|
-
"@tsed/core": "^6.
|
|
74
|
-
"@tsed/di": "^6.
|
|
75
|
-
"@tsed/json-mapper": "^6.
|
|
72
|
+
"@tsed/common": "^6.71.0",
|
|
73
|
+
"@tsed/core": "^6.71.0",
|
|
74
|
+
"@tsed/di": "^6.71.0",
|
|
75
|
+
"@tsed/json-mapper": "^6.71.0",
|
|
76
76
|
"@tsed/logger": "^5.16.0",
|
|
77
|
-
"@tsed/openspec": "^6.
|
|
78
|
-
"@tsed/schema": "^6.
|
|
77
|
+
"@tsed/openspec": "^6.71.0",
|
|
78
|
+
"@tsed/schema": "^6.71.0",
|
|
79
79
|
"koa": "2.13.0",
|
|
80
80
|
"koa-bodyparser": "4.3.0",
|
|
81
81
|
"koa-compress": "5.0.1",
|