@midwayjs/koa 3.20.5 → 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/dist/config/config.default.d.ts +7 -1
- package/dist/config/config.default.js +26 -21
- package/dist/configuration.js +2 -2
- package/dist/framework.d.ts +1 -2
- package/dist/framework.js +8 -13
- package/dist/middleware/bodyparser.middleware.js +2 -2
- package/dist/middleware/fav.middleware.js +2 -2
- package/package.json +7 -7
|
@@ -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
|
|
@@ -1,32 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.siteFile = exports.bodyParser = exports.onerror = exports.cookiesExtra = 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
|
-
var _a, _b, _c;
|
|
10
|
-
const ctx = info.ctx;
|
|
11
|
-
// format: '[$userId/$ip/$traceId/$use_ms $method $url]'
|
|
12
|
-
const userId = ctx.userId || '-';
|
|
13
|
-
const traceId = (_c = (_a = ctx.traceId) !== null && _a !== void 0 ? _a : (_b = ctx.tracer) === null || _b === void 0 ? void 0 : _b.traceId) !== null && _c !== void 0 ? _c : '-';
|
|
14
|
-
const use = Date.now() - ctx.startTime;
|
|
15
|
-
const label = userId +
|
|
16
|
-
'/' +
|
|
17
|
-
ctx.ip +
|
|
18
|
-
'/' +
|
|
19
|
-
traceId +
|
|
20
|
-
'/' +
|
|
21
|
-
use +
|
|
22
|
-
'ms ' +
|
|
23
|
-
ctx.method +
|
|
24
|
-
' ' +
|
|
25
|
-
ctx.url;
|
|
26
|
-
return `${info.timestamp} ${info.LEVEL} ${info.pid} [${label}] ${info.message}`;
|
|
27
|
-
},
|
|
28
8
|
serverTimeout: 2 * 60 * 1000,
|
|
29
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
|
+
};
|
|
30
35
|
/**
|
|
31
36
|
* The key that signing cookies. It can contain multiple keys seperated by `,`.
|
|
32
37
|
* @member {String} Config#keys
|
package/dist/configuration.js
CHANGED
|
@@ -27,6 +27,7 @@ let KoaConfiguration = class KoaConfiguration {
|
|
|
27
27
|
this.koaFramework.useMiddleware([fav_middleware_1.SiteFileMiddleware, bodyparser_middleware_1.BodyParserMiddleware]);
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
|
+
exports.KoaConfiguration = KoaConfiguration;
|
|
30
31
|
__decorate([
|
|
31
32
|
(0, core_1.Inject)(),
|
|
32
33
|
__metadata("design:type", core_1.MidwayDecoratorService)
|
|
@@ -45,7 +46,7 @@ __decorate([
|
|
|
45
46
|
__metadata("design:paramtypes", []),
|
|
46
47
|
__metadata("design:returntype", void 0)
|
|
47
48
|
], KoaConfiguration.prototype, "init", null);
|
|
48
|
-
KoaConfiguration = __decorate([
|
|
49
|
+
exports.KoaConfiguration = KoaConfiguration = __decorate([
|
|
49
50
|
(0, core_1.Configuration)({
|
|
50
51
|
namespace: 'koa',
|
|
51
52
|
imports: [session],
|
|
@@ -56,5 +57,4 @@ KoaConfiguration = __decorate([
|
|
|
56
57
|
],
|
|
57
58
|
})
|
|
58
59
|
], KoaConfiguration);
|
|
59
|
-
exports.KoaConfiguration = KoaConfiguration;
|
|
60
60
|
//# sourceMappingURL=configuration.js.map
|
package/dist/framework.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { BaseFramework, CommonFilterUnion, CommonMiddlewareUnion, IMidwayBootstrapOptions,
|
|
2
|
+
import { BaseFramework, CommonFilterUnion, CommonMiddlewareUnion, IMidwayBootstrapOptions, RouterInfo } from '@midwayjs/core';
|
|
3
3
|
import { IMidwayKoaApplication, IMidwayKoaConfigurationOptions, IMidwayKoaContext } from './interface';
|
|
4
4
|
import type { DefaultState, Middleware, Next } from 'koa';
|
|
5
5
|
import { Server } from 'http';
|
|
@@ -21,7 +21,6 @@ export declare class MidwayKoaFramework extends BaseFramework<IMidwayKoaApplicat
|
|
|
21
21
|
generateMiddleware(middlewareId: any): Promise<Middleware<DefaultState, IMidwayKoaContext, any>>;
|
|
22
22
|
run(): Promise<void>;
|
|
23
23
|
beforeStop(): Promise<void>;
|
|
24
|
-
getFrameworkType(): MidwayFrameworkType;
|
|
25
24
|
getFrameworkName(): string;
|
|
26
25
|
getServer(): Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
|
|
27
26
|
getPort(): string;
|
package/dist/framework.js
CHANGED
|
@@ -161,9 +161,8 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
|
|
|
161
161
|
}
|
|
162
162
|
async loadMidwayController() {
|
|
163
163
|
await this.generator.loadMidwayController(newRouter => {
|
|
164
|
-
var _a;
|
|
165
164
|
const dispatchFn = newRouter.middleware();
|
|
166
|
-
dispatchFn._name = `midwayController(${
|
|
165
|
+
dispatchFn._name = `midwayController(${newRouter?.opts?.prefix || '/'})`;
|
|
167
166
|
this.app.use(dispatchFn);
|
|
168
167
|
});
|
|
169
168
|
}
|
|
@@ -182,7 +181,6 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
|
|
|
182
181
|
return mwIns.resolve();
|
|
183
182
|
}
|
|
184
183
|
async run() {
|
|
185
|
-
var _a;
|
|
186
184
|
// load controller
|
|
187
185
|
await this.loadMidwayController();
|
|
188
186
|
// restore use method
|
|
@@ -193,9 +191,9 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
|
|
|
193
191
|
};
|
|
194
192
|
// https config
|
|
195
193
|
if (serverOptions.key && serverOptions.cert) {
|
|
196
|
-
serverOptions.key = core_1.
|
|
197
|
-
serverOptions.cert = core_1.
|
|
198
|
-
serverOptions.ca = core_1.
|
|
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);
|
|
199
197
|
process.env.MIDWAY_HTTP_SSL = 'true';
|
|
200
198
|
if (serverOptions.http2) {
|
|
201
199
|
this.server = require('http2').createSecureServer(serverOptions, this.app.callback());
|
|
@@ -219,7 +217,7 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
|
|
|
219
217
|
this.server.setTimeout(this.configurationOptions.serverTimeout);
|
|
220
218
|
}
|
|
221
219
|
// set port and listen server
|
|
222
|
-
const customPort =
|
|
220
|
+
const customPort = process.env.MIDWAY_HTTP_PORT ?? this.configurationOptions.port;
|
|
223
221
|
if (customPort) {
|
|
224
222
|
new Promise(resolve => {
|
|
225
223
|
const args = [customPort];
|
|
@@ -241,11 +239,8 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
|
|
|
241
239
|
});
|
|
242
240
|
}
|
|
243
241
|
}
|
|
244
|
-
getFrameworkType() {
|
|
245
|
-
return core_1.MidwayFrameworkType.WEB_KOA;
|
|
246
|
-
}
|
|
247
242
|
getFrameworkName() {
|
|
248
|
-
return '
|
|
243
|
+
return 'koa';
|
|
249
244
|
}
|
|
250
245
|
getServer() {
|
|
251
246
|
return this.server;
|
|
@@ -260,8 +255,8 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
|
|
|
260
255
|
this.filterManager.useFilter(Filter);
|
|
261
256
|
}
|
|
262
257
|
};
|
|
263
|
-
MidwayKoaFramework =
|
|
258
|
+
exports.MidwayKoaFramework = MidwayKoaFramework;
|
|
259
|
+
exports.MidwayKoaFramework = MidwayKoaFramework = __decorate([
|
|
264
260
|
(0, core_1.Framework)()
|
|
265
261
|
], MidwayKoaFramework);
|
|
266
|
-
exports.MidwayKoaFramework = MidwayKoaFramework;
|
|
267
262
|
//# sourceMappingURL=framework.js.map
|
|
@@ -23,12 +23,12 @@ let BodyParserMiddleware = class BodyParserMiddleware {
|
|
|
23
23
|
return 'bodyParser';
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
+
exports.BodyParserMiddleware = BodyParserMiddleware;
|
|
26
27
|
__decorate([
|
|
27
28
|
(0, core_1.Config)('bodyParser'),
|
|
28
29
|
__metadata("design:type", Object)
|
|
29
30
|
], BodyParserMiddleware.prototype, "bodyparserConfig", void 0);
|
|
30
|
-
BodyParserMiddleware = __decorate([
|
|
31
|
+
exports.BodyParserMiddleware = BodyParserMiddleware = __decorate([
|
|
31
32
|
(0, core_1.Middleware)()
|
|
32
33
|
], BodyParserMiddleware);
|
|
33
|
-
exports.BodyParserMiddleware = BodyParserMiddleware;
|
|
34
34
|
//# sourceMappingURL=bodyparser.middleware.js.map
|
|
@@ -51,12 +51,12 @@ let SiteFileMiddleware = class SiteFileMiddleware {
|
|
|
51
51
|
return 'siteFile';
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
|
+
exports.SiteFileMiddleware = SiteFileMiddleware;
|
|
54
55
|
__decorate([
|
|
55
56
|
(0, core_1.Config)('siteFile'),
|
|
56
57
|
__metadata("design:type", Object)
|
|
57
58
|
], SiteFileMiddleware.prototype, "siteFileConfig", void 0);
|
|
58
|
-
SiteFileMiddleware = __decorate([
|
|
59
|
+
exports.SiteFileMiddleware = SiteFileMiddleware = __decorate([
|
|
59
60
|
(0, core_1.Middleware)()
|
|
60
61
|
], SiteFileMiddleware);
|
|
61
|
-
exports.SiteFileMiddleware = SiteFileMiddleware;
|
|
62
62
|
//# sourceMappingURL=fav.middleware.js.map
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/koa",
|
|
3
|
-
"version": "
|
|
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",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"test": "node
|
|
10
|
-
"cov": "node
|
|
9
|
+
"test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
|
|
10
|
+
"cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit",
|
|
11
11
|
"ci": "npm run test"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
],
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@midwayjs/
|
|
27
|
+
"@midwayjs/core": "^4.0.0-beta.1",
|
|
28
|
+
"@midwayjs/mock": "^4.0.0-beta.1",
|
|
28
29
|
"@types/koa-router": "7.4.8",
|
|
29
30
|
"fs-extra": "11.3.0"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
33
|
"@koa/router": "^12.0.0",
|
|
33
34
|
"@midwayjs/cookies": "^1.3.0",
|
|
34
|
-
"@midwayjs/
|
|
35
|
-
"@midwayjs/session": "^3.20.5",
|
|
35
|
+
"@midwayjs/session": "^4.0.0-beta.1",
|
|
36
36
|
"@types/koa": "2.15.0",
|
|
37
37
|
"@types/qs": "6.9.18",
|
|
38
38
|
"koa": "2.16.1",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=12"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "832961ec3aff123c033197d8c00cb2bc9bad7ff8"
|
|
51
51
|
}
|