@midwayjs/koa 3.3.6 → 3.4.0-beta.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/framework.d.ts +1 -0
- package/dist/framework.js +16 -4
- package/dist/utils.js +1 -1
- package/package.json +6 -6
package/dist/framework.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { Server } from 'net';
|
|
|
6
6
|
export declare class MidwayKoaFramework extends BaseFramework<IMidwayKoaApplication, IMidwayKoaContext, IMidwayKoaConfigurationOptions, Next> {
|
|
7
7
|
private server;
|
|
8
8
|
private generator;
|
|
9
|
+
private webRouterService;
|
|
9
10
|
configure(): IMidwayKoaConfigurationOptions;
|
|
10
11
|
applicationInitialize(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
|
|
11
12
|
loadMidwayController(): Promise<void>;
|
package/dist/framework.js
CHANGED
|
@@ -15,9 +15,10 @@ const koa = require("koa");
|
|
|
15
15
|
const onerror_1 = require("./onerror");
|
|
16
16
|
const COOKIES = Symbol('context#cookies');
|
|
17
17
|
class KoaControllerGenerator extends core_1.WebControllerGenerator {
|
|
18
|
-
constructor(app) {
|
|
19
|
-
super(app);
|
|
18
|
+
constructor(app, webRouterService) {
|
|
19
|
+
super(app, webRouterService);
|
|
20
20
|
this.app = app;
|
|
21
|
+
this.webRouterService = webRouterService;
|
|
21
22
|
}
|
|
22
23
|
createRouter(routerOptions) {
|
|
23
24
|
const router = new Router(routerOptions);
|
|
@@ -68,16 +69,27 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
|
|
|
68
69
|
const midwayRootMiddleware = async (ctx, next) => {
|
|
69
70
|
this.app.createAnonymousContext(ctx);
|
|
70
71
|
await (await this.applyMiddleware(notFound))(ctx, next);
|
|
72
|
+
if (ctx.body === undefined &&
|
|
73
|
+
!ctx.response._explicitStatus &&
|
|
74
|
+
ctx._matchedRoute) {
|
|
75
|
+
// 如果进了路由,重新赋值,防止 404
|
|
76
|
+
ctx.body = undefined;
|
|
77
|
+
}
|
|
71
78
|
};
|
|
72
79
|
this.app.use(midwayRootMiddleware);
|
|
73
|
-
this.
|
|
80
|
+
this.webRouterService = await this.applicationContext.getAsync(core_1.MidwayWebRouterService, [
|
|
81
|
+
{
|
|
82
|
+
globalPrefix: this.configurationOptions.globalPrefix,
|
|
83
|
+
},
|
|
84
|
+
]);
|
|
85
|
+
this.generator = new KoaControllerGenerator(this.app, this.webRouterService);
|
|
74
86
|
this.defineApplicationProperties();
|
|
75
87
|
// hack use method
|
|
76
88
|
this.app.originUse = this.app.use;
|
|
77
89
|
this.app.use = this.app.useMiddleware;
|
|
78
90
|
}
|
|
79
91
|
async loadMidwayController() {
|
|
80
|
-
await this.generator.loadMidwayController(
|
|
92
|
+
await this.generator.loadMidwayController(newRouter => {
|
|
81
93
|
var _a;
|
|
82
94
|
const dispatchFn = newRouter.middleware();
|
|
83
95
|
dispatchFn._name = `midwayController(${((_a = newRouter === null || newRouter === void 0 ? void 0 : newRouter.opts) === null || _a === void 0 ? void 0 : _a.prefix) || '/'})`;
|
package/dist/utils.js
CHANGED
|
@@ -20,7 +20,7 @@ exports.accepts = accepts;
|
|
|
20
20
|
function acceptJSON(ctx) {
|
|
21
21
|
if (ctx.path.endsWith('.json'))
|
|
22
22
|
return true;
|
|
23
|
-
if (ctx.response.type &&
|
|
23
|
+
if (ctx.response.type && ctx.response.type.indexOf('json') >= 0)
|
|
24
24
|
return true;
|
|
25
25
|
if (ctx.accepts('html', 'text', 'json') === 'json')
|
|
26
26
|
return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/koa",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0-beta.2",
|
|
4
4
|
"description": "Midway Web Framework for KOA",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
],
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@midwayjs/decorator": "^3.
|
|
27
|
+
"@midwayjs/decorator": "^3.4.0-beta.2",
|
|
28
28
|
"@midwayjs/logger": "^2.15.0",
|
|
29
|
-
"@midwayjs/mock": "^3.
|
|
29
|
+
"@midwayjs/mock": "^3.4.0-beta.2",
|
|
30
30
|
"@types/koa": "2.13.4",
|
|
31
31
|
"@types/koa-router": "7.4.4",
|
|
32
32
|
"fs-extra": "10.0.1"
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@koa/router": "^10.0.0",
|
|
36
36
|
"@midwayjs/cookies": "^1.0.2",
|
|
37
|
-
"@midwayjs/core": "^3.
|
|
38
|
-
"@midwayjs/session": "^3.
|
|
37
|
+
"@midwayjs/core": "^3.4.0-beta.2",
|
|
38
|
+
"@midwayjs/session": "^3.4.0-beta.2",
|
|
39
39
|
"koa": "2.13.4",
|
|
40
40
|
"koa-bodyparser": "4.3.0"
|
|
41
41
|
},
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=12"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "a61721d3946b30fd4cac183265edcd99b31ac72b"
|
|
51
51
|
}
|