@midwayjs/koa 3.0.13 → 3.1.2

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/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -68,7 +68,7 @@ interface BodyParserOptions {
68
68
  /**
69
69
  * requested encoding. Default is utf-8 by co-body
70
70
  */
71
- encode?: string;
71
+ encoding?: string;
72
72
  /**
73
73
  * limit of the urlencoded body. If the body ends up being larger than this limit
74
74
  * a 413 error code is returned. Default is 56kb
package/dist/onerror.js CHANGED
@@ -177,7 +177,7 @@ function setupOnError(app, config, logger) {
177
177
  }
178
178
  }
179
179
  if (type === 'json') {
180
- this.body = decorator_1.Utils.safeStringify(this.body);
180
+ this.body = JSON.stringify(this.body);
181
181
  }
182
182
  this.res.end(this.body);
183
183
  };
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare function detectStatus(err: any): any;
2
- export declare function accepts(ctx: any): "json" | "js" | "html";
2
+ export declare function accepts(ctx: any): "json" | "html";
3
3
  export declare function sendToWormhole(stream: any): Promise<void>;
4
4
  export declare function isProduction(app: any): boolean;
5
5
  export declare const tpl = "\n<!DOCTYPE html>\n<html>\n <head>\n <title>Error - {{status}}</title>\n <meta name=\"viewport\" content=\"user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0\">\n\n <style>\n body {\n padding: 50px 80px;\n font: 14px \"Helvetica Neue\", Helvetica, sans-serif;\n }\n\n h1 {\n font-size: 2em;\n margin-bottom: 5px;\n }\n\n pre {\n font-size: .8em;\n }\n </style>\n </head>\n <body>\n <div id=\"error\">\n <h1>Error</h1>\n <p>Looks like something broke!</p>\n <p><h2>Stack</h2></p>\n <pre>\n <code>\n{{stack}}\n </code>\n </pre>\n <p><h2>Error Code</h2></p>\n <pre>\n <code>\n{{errorCode}}\n </code>\n </pre>\n </div>\n </body>\n</html>";
package/dist/utils.js CHANGED
@@ -12,13 +12,20 @@ function detectStatus(err) {
12
12
  }
13
13
  exports.detectStatus = detectStatus;
14
14
  function accepts(ctx) {
15
- if (ctx.acceptJSON)
15
+ if (acceptJSON(ctx))
16
16
  return 'json';
17
- if (ctx.acceptJSONP)
18
- return 'js';
19
17
  return 'html';
20
18
  }
21
19
  exports.accepts = accepts;
20
+ function acceptJSON(ctx) {
21
+ if (ctx.path.endsWith('.json'))
22
+ return true;
23
+ if (ctx.response.type && this.response.type.indexOf('json') >= 0)
24
+ return true;
25
+ if (ctx.accepts('html', 'text', 'json') === 'json')
26
+ return true;
27
+ return false;
28
+ }
22
29
  function sendToWormhole(stream) {
23
30
  return new Promise(resolve => {
24
31
  if (typeof stream.resume !== 'function') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/koa",
3
- "version": "3.0.13",
3
+ "version": "3.1.2",
4
4
  "description": "Midway Web Framework for KOA",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "devDependencies": {
26
26
  "@midwayjs/decorator": "^3.0.10",
27
27
  "@midwayjs/logger": "^2.15.0",
28
- "@midwayjs/mock": "^3.0.13",
28
+ "@midwayjs/mock": "^3.1.2",
29
29
  "@types/koa": "2.13.4",
30
30
  "@types/koa-router": "7.4.4",
31
31
  "fs-extra": "10.0.1"
@@ -33,8 +33,8 @@
33
33
  "dependencies": {
34
34
  "@koa/router": "^10.0.0",
35
35
  "@midwayjs/cookies": "1.0.1",
36
- "@midwayjs/core": "^3.0.13",
37
- "@midwayjs/session": "^3.0.13",
36
+ "@midwayjs/core": "^3.1.2",
37
+ "@midwayjs/session": "^3.1.2",
38
38
  "koa": "2.13.4",
39
39
  "koa-bodyparser": "4.3.0"
40
40
  },
@@ -46,5 +46,5 @@
46
46
  "engines": {
47
47
  "node": ">=12"
48
48
  },
49
- "gitHead": "8c8338f4488ec65765c342dd5238ed3e61872b37"
49
+ "gitHead": "4ff3aa892b76d016f0ea123c7f9520d054d5c96b"
50
50
  }