@midwayjs/koa 3.0.1 → 3.0.4

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.
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * koa server options
3
3
  */
4
- export declare const koa: {};
4
+ export declare const koa: {
5
+ contextLoggerFormat: (info: any) => string;
6
+ };
5
7
  /**
6
8
  * The key that signing cookies. It can contain multiple keys seperated by `,`.
7
9
  * @member {String} Config#keys
@@ -4,7 +4,27 @@ exports.siteFile = exports.bodyParser = exports.onerror = exports.cookies = expo
4
4
  /**
5
5
  * koa server options
6
6
  */
7
- exports.koa = {};
7
+ exports.koa = {
8
+ contextLoggerFormat: info => {
9
+ const ctx = info.ctx;
10
+ // format: '[$userId/$ip/$traceId/$use_ms $method $url]'
11
+ const userId = ctx.userId || '-';
12
+ const traceId = (ctx.tracer && ctx.tracer.traceId) || '-';
13
+ const use = Date.now() - ctx.startTime;
14
+ const label = userId +
15
+ '/' +
16
+ ctx.ip +
17
+ '/' +
18
+ traceId +
19
+ '/' +
20
+ use +
21
+ 'ms ' +
22
+ ctx.method +
23
+ ' ' +
24
+ ctx.url;
25
+ return `${info.timestamp} ${info.LEVEL} ${info.pid} [${label}] ${info.message}`;
26
+ },
27
+ };
8
28
  /**
9
29
  * The key that signing cookies. It can contain multiple keys seperated by `,`.
10
30
  * @member {String} Config#keys
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export { MidwayKoaFramework as Framework } from './framework';
2
- export { MidwayKoaContextLogger } from './logger';
3
2
  export * from './interface';
4
3
  export { KoaConfiguration as Configuration } from './configuration';
5
4
  export * from './middleware/fav.middleware';
package/dist/index.js CHANGED
@@ -10,11 +10,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.Configuration = exports.MidwayKoaContextLogger = exports.Framework = void 0;
13
+ exports.Configuration = exports.Framework = void 0;
14
14
  var framework_1 = require("./framework");
15
15
  Object.defineProperty(exports, "Framework", { enumerable: true, get: function () { return framework_1.MidwayKoaFramework; } });
16
- var logger_1 = require("./logger");
17
- Object.defineProperty(exports, "MidwayKoaContextLogger", { enumerable: true, get: function () { return logger_1.MidwayKoaContextLogger; } });
18
16
  __exportStar(require("./interface"), exports);
19
17
  var configuration_1 = require("./configuration");
20
18
  Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.KoaConfiguration; } });
package/dist/onerror.js CHANGED
@@ -54,6 +54,7 @@ function setupOnerror(app, config, logger) {
54
54
  }
55
55
  ctx.body = utils_1.tpl
56
56
  .replace('{{status}}', (0, utils_1.escapeHtml)(err.status))
57
+ .replace('{{errorCode}}', (0, utils_1.escapeHtml)(err.code))
57
58
  .replace('{{stack}}', (0, utils_1.escapeHtml)(err.stack));
58
59
  ctx.type = 'html';
59
60
  },
package/dist/utils.d.ts CHANGED
@@ -2,7 +2,7 @@ export declare function detectStatus(err: any): any;
2
2
  export declare function accepts(ctx: any): "json" | "js" | "html";
3
3
  export declare function sendToWormhole(stream: any): Promise<void>;
4
4
  export declare function isProduction(app: any): boolean;
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 <pre>\n <code>\n{{stack}}\n </code>\n </pre>\n </div>\n </body>\n</html>";
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>";
6
6
  /**
7
7
  * Escape special characters in the given string of text.
8
8
  *
package/dist/utils.js CHANGED
@@ -84,11 +84,18 @@ exports.tpl = `
84
84
  <div id="error">
85
85
  <h1>Error</h1>
86
86
  <p>Looks like something broke!</p>
87
+ <p><h2>Stack</h2></p>
87
88
  <pre>
88
89
  <code>
89
90
  {{stack}}
90
91
  </code>
91
92
  </pre>
93
+ <p><h2>Error Code</h2></p>
94
+ <pre>
95
+ <code>
96
+ {{errorCode}}
97
+ </code>
98
+ </pre>
92
99
  </div>
93
100
  </body>
94
101
  </html>`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/koa",
3
- "version": "3.0.1",
3
+ "version": "3.0.4",
4
4
  "description": "Midway Web Framework for KOA",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -23,9 +23,9 @@
23
23
  ],
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@midwayjs/decorator": "^3.0.0",
27
- "@midwayjs/logger": "^2.14.0",
28
- "@midwayjs/mock": "^3.0.1",
26
+ "@midwayjs/decorator": "^3.0.4",
27
+ "@midwayjs/logger": "^2.15.0",
28
+ "@midwayjs/mock": "^3.0.4",
29
29
  "@types/koa": "2.13.4",
30
30
  "@types/koa-router": "7.4.4",
31
31
  "fs-extra": "10.0.0"
@@ -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.1",
37
- "@midwayjs/session": "^3.0.1",
36
+ "@midwayjs/core": "^3.0.4",
37
+ "@midwayjs/session": "^3.0.4",
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": "f345b4ed0392e5c3b9e815438ef0a377ad6da076"
49
+ "gitHead": "c2a37dd026c7bf3e855f4498691f572ef61396e3"
50
50
  }
package/dist/logger.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { MidwayContextLogger } from '@midwayjs/logger';
2
- import { IMidwayKoaContext } from './interface';
3
- export declare class MidwayKoaContextLogger extends MidwayContextLogger<IMidwayKoaContext> {
4
- formatContextLabel(): string;
5
- }
6
- //# sourceMappingURL=logger.d.ts.map
package/dist/logger.js DELETED
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidwayKoaContextLogger = void 0;
4
- const logger_1 = require("@midwayjs/logger");
5
- class MidwayKoaContextLogger extends logger_1.MidwayContextLogger {
6
- formatContextLabel() {
7
- const ctx = this.ctx;
8
- // format: '[$userId/$ip/$traceId/$use_ms $method $url]'
9
- const userId = ctx.userId || '-';
10
- const traceId = (ctx.tracer && ctx.tracer.traceId) || '-';
11
- const use = Date.now() - ctx.startTime;
12
- return (userId +
13
- '/' +
14
- ctx.ip +
15
- '/' +
16
- traceId +
17
- '/' +
18
- use +
19
- 'ms ' +
20
- ctx.method +
21
- ' ' +
22
- ctx.url);
23
- }
24
- }
25
- exports.MidwayKoaContextLogger = MidwayKoaContextLogger;
26
- //# sourceMappingURL=logger.js.map