@midwayjs/koa 4.0.0-alpha.1 → 4.0.0-beta.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/README.md CHANGED
@@ -9,4 +9,4 @@ Document: [https://midwayjs.org](https://midwayjs.org)
9
9
 
10
10
  ## License
11
11
 
12
- [MIT]((http://github.com/midwayjs/midway/blob/master/LICENSE))
12
+ [MIT]((https://github.com/midwayjs/midway/blob/master/LICENSE))
@@ -2,9 +2,15 @@
2
2
  * koa server options
3
3
  */
4
4
  export declare const koa: {
5
- contextLoggerFormat: (info: any) => string;
6
5
  serverTimeout: number;
7
6
  };
7
+ export declare const midwayLogger: {
8
+ clients: {
9
+ appLogger: {
10
+ contextLoggerFormat: (info: any) => string;
11
+ };
12
+ };
13
+ };
8
14
  /**
9
15
  * The key that signing cookies. It can contain multiple keys seperated by `,`.
10
16
  * @member {String} Config#keys
@@ -18,6 +24,12 @@ export declare const keys = "";
18
24
  * @property {Boolean} httpOnly - httpOnly property, defaults is true
19
25
  */
20
26
  export declare const cookies: {};
27
+ /**
28
+ * default cookie get options
29
+ */
30
+ export declare const cookiesExtra: {
31
+ defaultGetOptions: {};
32
+ };
21
33
  export declare const onerror: {};
22
34
  /**
23
35
  * @member Config#bodyParser
@@ -1,31 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.siteFile = exports.bodyParser = exports.onerror = exports.cookies = exports.keys = exports.koa = void 0;
3
+ exports.siteFile = exports.bodyParser = exports.onerror = exports.cookiesExtra = exports.cookies = exports.keys = exports.midwayLogger = exports.koa = void 0;
4
4
  /**
5
5
  * koa server options
6
6
  */
7
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.traceId ?? 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
  serverTimeout: 2 * 60 * 1000,
28
9
  };
10
+ exports.midwayLogger = {
11
+ clients: {
12
+ appLogger: {
13
+ contextLoggerFormat: info => {
14
+ const ctx = info.ctx;
15
+ // format: '[$userId/$ip/$traceId/$use_ms $method $url]'
16
+ const userId = ctx.userId || '-';
17
+ const traceId = ctx.traceId ?? ctx.tracer?.traceId ?? '-';
18
+ const use = Date.now() - ctx.startTime;
19
+ const label = userId +
20
+ '/' +
21
+ ctx.ip +
22
+ '/' +
23
+ traceId +
24
+ '/' +
25
+ use +
26
+ 'ms ' +
27
+ ctx.method +
28
+ ' ' +
29
+ ctx.url;
30
+ return `${info.timestamp} ${info.LEVEL} ${info.pid} [${label}] ${info.message}`;
31
+ },
32
+ },
33
+ },
34
+ };
29
35
  /**
30
36
  * The key that signing cookies. It can contain multiple keys seperated by `,`.
31
37
  * @member {String} Config#keys
@@ -42,6 +48,14 @@ exports.cookies = {
42
48
  // httpOnly: true | false,
43
49
  // sameSite: 'none|lax|strict',
44
50
  };
51
+ /**
52
+ * default cookie get options
53
+ */
54
+ exports.cookiesExtra = {
55
+ defaultGetOptions: {
56
+ // sign: false,
57
+ },
58
+ };
45
59
  exports.onerror = {};
46
60
  /**
47
61
  * @member Config#bodyParser
package/dist/framework.js CHANGED
@@ -41,6 +41,7 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
41
41
  throw new core_1.MidwayConfigMissingError('config.keys');
42
42
  }
43
43
  const cookieOptions = this.configService.getConfiguration('cookies');
44
+ const cookieGetOptions = this.configService.getConfiguration('cookiesExtra.defaultGetOptions');
44
45
  this.app = new koa({
45
46
  keys: [].concat(appKeys),
46
47
  proxy: this.configurationOptions.proxy,
@@ -51,7 +52,7 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
51
52
  Object.defineProperty(this.app.context, 'cookies', {
52
53
  get() {
53
54
  if (!this[COOKIES]) {
54
- this[COOKIES] = new cookies_1.Cookies(this, this.app.keys, cookieOptions);
55
+ this[COOKIES] = new cookies_1.Cookies(this, this.app.keys, cookieOptions, cookieGetOptions);
55
56
  }
56
57
  return this[COOKIES];
57
58
  },
@@ -190,9 +191,9 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
190
191
  };
191
192
  // https config
192
193
  if (serverOptions.key && serverOptions.cert) {
193
- serverOptions.key = core_1.PathFileUtil.getFileContentSync(serverOptions.key);
194
- serverOptions.cert = core_1.PathFileUtil.getFileContentSync(serverOptions.cert);
195
- serverOptions.ca = core_1.PathFileUtil.getFileContentSync(serverOptions.ca);
194
+ serverOptions.key = core_1.PathFileUtils.getFileContentSync(serverOptions.key);
195
+ serverOptions.cert = core_1.PathFileUtils.getFileContentSync(serverOptions.cert);
196
+ serverOptions.ca = core_1.PathFileUtils.getFileContentSync(serverOptions.ca);
196
197
  process.env.MIDWAY_HTTP_SSL = 'true';
197
198
  if (serverOptions.http2) {
198
199
  this.server = require('http2').createSecureServer(serverOptions, this.app.callback());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/koa",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "Midway Web Framework for KOA",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -24,20 +24,20 @@
24
24
  ],
25
25
  "license": "MIT",
26
26
  "devDependencies": {
27
- "@midwayjs/core": "^4.0.0-alpha.1",
28
- "@midwayjs/mock": "^4.0.0-alpha.1",
27
+ "@midwayjs/core": "^4.0.0-beta.1",
28
+ "@midwayjs/mock": "^4.0.0-beta.1",
29
29
  "@types/koa-router": "7.4.8",
30
- "fs-extra": "11.2.0"
30
+ "fs-extra": "11.3.0"
31
31
  },
32
32
  "dependencies": {
33
33
  "@koa/router": "^12.0.0",
34
- "@midwayjs/cookies": "^1.0.2",
35
- "@midwayjs/session": "^4.0.0-alpha.1",
34
+ "@midwayjs/cookies": "^1.3.0",
35
+ "@midwayjs/session": "^4.0.0-beta.1",
36
36
  "@types/koa": "2.15.0",
37
- "@types/qs": "6.9.17",
38
- "koa": "2.15.3",
37
+ "@types/qs": "6.9.18",
38
+ "koa": "2.16.1",
39
39
  "koa-bodyparser": "4.4.1",
40
- "qs": "6.13.1"
40
+ "qs": "6.14.0"
41
41
  },
42
42
  "author": "Harry Chen <czy88840616@gmail.com>",
43
43
  "repository": {
@@ -47,5 +47,5 @@
47
47
  "engines": {
48
48
  "node": ">=12"
49
49
  },
50
- "gitHead": "14bb4da91805a1cf52f190c0d37a74b395dd6372"
50
+ "gitHead": "832961ec3aff123c033197d8c00cb2bc9bad7ff8"
51
51
  }