@celljs/mvc 3.9.0 → 4.1.0
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/esm/node/view/file-view.js +1 -2
- package/esm/node/view/file-view.js.map +1 -1
- package/esm/node/view/html-view.js +1 -2
- package/esm/node/view/html-view.js.map +1 -1
- package/lib/node/mvc-http.spec.d.ts +2 -0
- package/lib/node/mvc-http.spec.d.ts.map +1 -0
- package/lib/node/mvc-http.spec.js +540 -0
- package/lib/node/mvc-http.spec.js.map +1 -0
- package/lib/node/view/file-view.js +2 -2
- package/lib/node/view/file-view.js.map +1 -1
- package/lib/node/view/html-view.js +2 -2
- package/lib/node/view/html-view.js.map +1 -1
- package/package.json +12 -18
- package/src/node/mvc-http.spec.ts +359 -0
- package/src/node/view/file-view.ts +1 -1
- package/src/node/view/html-view.ts +1 -1
|
@@ -16,8 +16,7 @@ import { View } from './view-protocol.js';
|
|
|
16
16
|
import { HttpHeaders, HttpStatus, MediaType } from '@celljs/http';
|
|
17
17
|
import { Context } from '@celljs/web/lib/node';
|
|
18
18
|
import { FILE_VIEW_NAME } from '../annotation/file.js';
|
|
19
|
-
import
|
|
20
|
-
const { createReadStream } = __cellCjs0;
|
|
19
|
+
import { createReadStream } from 'node:fs';
|
|
21
20
|
import { join } from 'path';
|
|
22
21
|
let FileView = class FileView {
|
|
23
22
|
constructor() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-view.js","sourceRoot":"","sources":["../../../src/node/view/file-view.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,OAAO,EAAY,MAAM,sBAAsB,CA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AO,CAAC,EAAE,QAAQ,EAAgB;QAC9B,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,KAAK,cAAc,CAAC,CAAC;IACxD,CAAC;CACJ,CAAA;AAjDsB;IADlB,SAAS,CAAC,MAAM,CAAC;;wCACgB;AAGf;IADlB,KAAK,CAAC,sBAAsB,CAAC;;6CACM;AAV3B,QAAQ;IADpB,SAAS,CAAC,IAAI,CAAC;GACH,QAAQ,CAwDpB"}
|
|
@@ -16,8 +16,7 @@ import { View } from './view-protocol.js';
|
|
|
16
16
|
import { Context } from '@celljs/web/lib/node';
|
|
17
17
|
import Mustache from 'mustache';
|
|
18
18
|
import { join } from 'path';
|
|
19
|
-
import
|
|
20
|
-
const { readFile } = __cellCjs1;
|
|
19
|
+
import { readFile } from 'node:fs/promises';
|
|
21
20
|
import { HTML_VIEW_NAME } from '../annotation/html.js';
|
|
22
21
|
import { MediaType } from '@celljs/http';
|
|
23
22
|
let HtmlView = class HtmlView {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-view.js","sourceRoot":"","sources":["../../../src/node/view/html-view.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"html-view.js","sourceRoot":"","sources":["../../../src/node/view/html-view.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,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AAPvB,QAAQ;IADpB,SAAS,CAAC,IAAI,CAAC;GACH,QAAQ,CAsBpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mvc-http.spec.d.ts","sourceRoot":"","sources":["../../src/node/mvc-http.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const bun_test_1 = require("bun:test");
|
|
19
|
+
const chai_1 = require("chai");
|
|
20
|
+
const node_http_1 = require("node:http");
|
|
21
|
+
const node_module_1 = require("node:module");
|
|
22
|
+
// 按 CLI 生成的后端入口加载顺序导入:core 的 static module → web 的 module → mvc 的 module(见 @celljs/vite 的
|
|
23
|
+
// ContainerGenerator 与各包 package.json 的 cell 字段)。不要导入 application-factory:它会顺带登记 CommonApplication,
|
|
24
|
+
// 和 node 的 BackendApplication 冲突。
|
|
25
|
+
const static_module_1 = __importDefault(require("@celljs/core/lib/common/static-module"));
|
|
26
|
+
const static_module_2 = __importDefault(require("@celljs/core/lib/node/static-module"));
|
|
27
|
+
const module_1 = __importDefault(require("@celljs/web/lib/common/module"));
|
|
28
|
+
const module_2 = __importDefault(require("@celljs/web/lib/node/module"));
|
|
29
|
+
const module_3 = __importDefault(require("./module"));
|
|
30
|
+
const container_factory_1 = require("@celljs/core/lib/common/container/container-factory");
|
|
31
|
+
const container_provider_1 = require("@celljs/core/lib/common/container/container-provider");
|
|
32
|
+
const auto_bind_1 = require("@celljs/core/lib/common/container/auto-bind");
|
|
33
|
+
const utils_1 = require("@celljs/core/lib/common/utils");
|
|
34
|
+
const application_protocol_1 = require("@celljs/core/lib/common/application/application-protocol");
|
|
35
|
+
const node_1 = require("@celljs/web/lib/node");
|
|
36
|
+
const annotation_1 = require("./annotation");
|
|
37
|
+
/**
|
|
38
|
+
* mvc 的 HTTP 行为约定(阶段 1.E 行为测试):经真实 HTTP 请求断言路由、参数解析、响应与异常。
|
|
39
|
+
*
|
|
40
|
+
* 请求路径与 express-adapter 的 http-application-entry 相同:express 收到请求 → new Context(req, res) →
|
|
41
|
+
* Context.run → Dispatcher.dispatch。express 是 @celljs/web 的依赖,这里从 web 的位置解析,mvc 不新增依赖。
|
|
42
|
+
* 配置是 core / web / mvc / http 的 cell.yml 合并后的默认值(CLI 会做这一步;这里照抄,保持与 cell.yml 一致)。
|
|
43
|
+
* 阶段 2 换 HTTP 管线时,只需要替换 serve(),用例本身不用改。
|
|
44
|
+
*/
|
|
45
|
+
const express = (0, node_module_1.createRequire)(require.resolve('@celljs/web/package.json'))('express');
|
|
46
|
+
const DEFAULT_CONFIG = {
|
|
47
|
+
cell: {
|
|
48
|
+
// core/cell.yml
|
|
49
|
+
name: 'Cell Framework', annotation: { Component: { proxy: false } }, aop: { enabled: true }, logger: { level: 'error' }, tenant: { enabled: false },
|
|
50
|
+
// web/cell.yml(含 backend 段)
|
|
51
|
+
session: { autoCommit: true, maxAge: 86400000, sessionIdKey: 'cell:sessionId', sessionKey: 'cell:session' },
|
|
52
|
+
server: { path: '/', port: 3000, host: '127.0.0.1', endpoint: 'http://localhost:${cell.server.port}' },
|
|
53
|
+
trace: { requestField: 'X-Cell-Trace-ID', responseField: 'X-Cell-Trace-ID' },
|
|
54
|
+
health: { url: '/health', method: 'GET' },
|
|
55
|
+
web: { route: { cacheSize: 500 }, validationPipeOptions: { detailedOutputDisabled: false, transformEnabled: true } },
|
|
56
|
+
cookies: { keys: ['abcdef'] },
|
|
57
|
+
// mvc/cell.yml
|
|
58
|
+
mvc: { path: '/*', defaultViewName: 'json', baseFileDir: 'assets' },
|
|
59
|
+
mustache: { cache: false, baseViewDir: 'assets/views' },
|
|
60
|
+
// http/cell.yml
|
|
61
|
+
client: { config: { withCredentials: true, headers: { 'X-Requested-With': 'XMLHttpRequest' } } },
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
let server;
|
|
65
|
+
(0, bun_test_1.afterEach)(async () => {
|
|
66
|
+
await new Promise(r => (server ? server.close(() => r()) : r()));
|
|
67
|
+
server = undefined;
|
|
68
|
+
});
|
|
69
|
+
/** 启动应用(在调用之前定义好的控制器都会被装配),返回指向它的 fetch。 */
|
|
70
|
+
async function serve() {
|
|
71
|
+
utils_1.currentThis.cellProps = structuredClone(DEFAULT_CONFIG);
|
|
72
|
+
const container = container_factory_1.ContainerFactory.create(static_module_1.default, static_module_2.default, module_1.default, module_2.default, module_3.default, (0, auto_bind_1.autoBind)());
|
|
73
|
+
container_provider_1.ContainerProvider.set(container);
|
|
74
|
+
const app = container.get(application_protocol_1.Application);
|
|
75
|
+
await app.start();
|
|
76
|
+
const handler = express();
|
|
77
|
+
handler.all('*', (req, res) => {
|
|
78
|
+
const ctx = new node_1.Context(req, res);
|
|
79
|
+
node_1.Context.run(() => container.get(node_1.Dispatcher).dispatch(ctx));
|
|
80
|
+
});
|
|
81
|
+
server = (0, node_http_1.createServer)(handler);
|
|
82
|
+
await new Promise(r => server.listen(0, '127.0.0.1', r));
|
|
83
|
+
const base = `http://127.0.0.1:${server.address().port}`;
|
|
84
|
+
return (path, init) => fetch(base + path, init);
|
|
85
|
+
}
|
|
86
|
+
const JSON_HEADERS = { 'content-type': 'application/json' };
|
|
87
|
+
(0, bun_test_1.describe)('mvc 路由', () => {
|
|
88
|
+
(0, bun_test_1.it)('按控制器前缀 + 方法路径匹配;HTTP 方法不同走不同处理函数', async () => {
|
|
89
|
+
let Items = class Items {
|
|
90
|
+
list() { return ['a', 'b']; }
|
|
91
|
+
one(id) { return { id }; }
|
|
92
|
+
create() { return 'created'; }
|
|
93
|
+
replace(id) { return `put ${id}`; }
|
|
94
|
+
patch(id) { return `patch ${id}`; }
|
|
95
|
+
remove(id) { return `deleted ${id}`; }
|
|
96
|
+
};
|
|
97
|
+
__decorate([
|
|
98
|
+
(0, annotation_1.Get)(),
|
|
99
|
+
__metadata("design:type", Function),
|
|
100
|
+
__metadata("design:paramtypes", []),
|
|
101
|
+
__metadata("design:returntype", void 0)
|
|
102
|
+
], Items.prototype, "list", null);
|
|
103
|
+
__decorate([
|
|
104
|
+
(0, annotation_1.Get)(':id'),
|
|
105
|
+
__param(0, (0, annotation_1.Param)('id')),
|
|
106
|
+
__metadata("design:type", Function),
|
|
107
|
+
__metadata("design:paramtypes", [String]),
|
|
108
|
+
__metadata("design:returntype", void 0)
|
|
109
|
+
], Items.prototype, "one", null);
|
|
110
|
+
__decorate([
|
|
111
|
+
(0, annotation_1.Post)(),
|
|
112
|
+
__metadata("design:type", Function),
|
|
113
|
+
__metadata("design:paramtypes", []),
|
|
114
|
+
__metadata("design:returntype", void 0)
|
|
115
|
+
], Items.prototype, "create", null);
|
|
116
|
+
__decorate([
|
|
117
|
+
(0, annotation_1.Put)(':id'),
|
|
118
|
+
__param(0, (0, annotation_1.Param)('id')),
|
|
119
|
+
__metadata("design:type", Function),
|
|
120
|
+
__metadata("design:paramtypes", [String]),
|
|
121
|
+
__metadata("design:returntype", void 0)
|
|
122
|
+
], Items.prototype, "replace", null);
|
|
123
|
+
__decorate([
|
|
124
|
+
(0, annotation_1.Patch)(':id'),
|
|
125
|
+
__param(0, (0, annotation_1.Param)('id')),
|
|
126
|
+
__metadata("design:type", Function),
|
|
127
|
+
__metadata("design:paramtypes", [String]),
|
|
128
|
+
__metadata("design:returntype", void 0)
|
|
129
|
+
], Items.prototype, "patch", null);
|
|
130
|
+
__decorate([
|
|
131
|
+
(0, annotation_1.Delete)(':id'),
|
|
132
|
+
__param(0, (0, annotation_1.Param)('id')),
|
|
133
|
+
__metadata("design:type", Function),
|
|
134
|
+
__metadata("design:paramtypes", [String]),
|
|
135
|
+
__metadata("design:returntype", void 0)
|
|
136
|
+
], Items.prototype, "remove", null);
|
|
137
|
+
Items = __decorate([
|
|
138
|
+
(0, annotation_1.Controller)('items')
|
|
139
|
+
], Items);
|
|
140
|
+
const f = await serve();
|
|
141
|
+
(0, chai_1.expect)(await (await f('/items')).json()).to.deep.equal(['a', 'b']);
|
|
142
|
+
(0, chai_1.expect)(await (await f('/items/42')).json()).to.deep.equal({ id: '42' });
|
|
143
|
+
(0, chai_1.expect)(await (await f('/items', { method: 'POST' })).json()).to.equal('created');
|
|
144
|
+
(0, chai_1.expect)(await (await f('/items/1', { method: 'PUT' })).json()).to.equal('put 1');
|
|
145
|
+
(0, chai_1.expect)(await (await f('/items/1', { method: 'PATCH' })).json()).to.equal('patch 1');
|
|
146
|
+
(0, chai_1.expect)(await (await f('/items/1', { method: 'DELETE' })).json()).to.equal('deleted 1');
|
|
147
|
+
(0, chai_1.expect)(Items).to.be.a('function');
|
|
148
|
+
});
|
|
149
|
+
(0, bun_test_1.it)('没有前缀的控制器;@All 匹配所有方法', async () => {
|
|
150
|
+
let Root = class Root {
|
|
151
|
+
home() { return 'home'; }
|
|
152
|
+
any() { return 'any'; }
|
|
153
|
+
};
|
|
154
|
+
__decorate([
|
|
155
|
+
(0, annotation_1.Get)(),
|
|
156
|
+
(0, annotation_1.Text)(),
|
|
157
|
+
__metadata("design:type", Function),
|
|
158
|
+
__metadata("design:paramtypes", []),
|
|
159
|
+
__metadata("design:returntype", void 0)
|
|
160
|
+
], Root.prototype, "home", null);
|
|
161
|
+
__decorate([
|
|
162
|
+
(0, annotation_1.All)('any'),
|
|
163
|
+
(0, annotation_1.Text)(),
|
|
164
|
+
__metadata("design:type", Function),
|
|
165
|
+
__metadata("design:paramtypes", []),
|
|
166
|
+
__metadata("design:returntype", void 0)
|
|
167
|
+
], Root.prototype, "any", null);
|
|
168
|
+
Root = __decorate([
|
|
169
|
+
(0, annotation_1.Controller)()
|
|
170
|
+
], Root);
|
|
171
|
+
const f = await serve();
|
|
172
|
+
(0, chai_1.expect)(await (await f('/')).text()).to.equal('home');
|
|
173
|
+
for (const method of ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']) {
|
|
174
|
+
(0, chai_1.expect)(await (await f('/any', { method })).text()).to.equal('any');
|
|
175
|
+
}
|
|
176
|
+
(0, chai_1.expect)(Root).to.be.a('function');
|
|
177
|
+
});
|
|
178
|
+
(0, bun_test_1.it)('没有匹配的路由返回 404,错误信息里有方法和路径', async () => {
|
|
179
|
+
let Only = class Only {
|
|
180
|
+
get() { return 1; }
|
|
181
|
+
};
|
|
182
|
+
__decorate([
|
|
183
|
+
(0, annotation_1.Get)(),
|
|
184
|
+
__metadata("design:type", Function),
|
|
185
|
+
__metadata("design:paramtypes", []),
|
|
186
|
+
__metadata("design:returntype", void 0)
|
|
187
|
+
], Only.prototype, "get", null);
|
|
188
|
+
Only = __decorate([
|
|
189
|
+
(0, annotation_1.Controller)('only')
|
|
190
|
+
], Only);
|
|
191
|
+
const f = await serve();
|
|
192
|
+
const res = await f('/nowhere');
|
|
193
|
+
(0, chai_1.expect)(res.status).to.equal(404);
|
|
194
|
+
(0, chai_1.expect)(await res.text()).to.contain('/nowhere');
|
|
195
|
+
(0, chai_1.expect)((await f('/only', { method: 'POST' })).status).to.equal(404);
|
|
196
|
+
(0, chai_1.expect)(Only).to.be.a('function');
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
(0, bun_test_1.describe)('mvc 参数解析', () => {
|
|
200
|
+
(0, bun_test_1.it)('@Param / @Query / @Body / @Header 取单个值或整体', async () => {
|
|
201
|
+
let Args = class Args {
|
|
202
|
+
all(a, params, q, query, name, body, probe, headers) {
|
|
203
|
+
return { a, params, q, query, name, body, probe, hasHost: !!headers.host };
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
__decorate([
|
|
207
|
+
(0, annotation_1.Post)(':a/:b'),
|
|
208
|
+
__param(0, (0, annotation_1.Param)('a')),
|
|
209
|
+
__param(1, (0, annotation_1.Param)()),
|
|
210
|
+
__param(2, (0, annotation_1.Query)('q')),
|
|
211
|
+
__param(3, (0, annotation_1.Query)()),
|
|
212
|
+
__param(4, (0, annotation_1.Body)('name')),
|
|
213
|
+
__param(5, (0, annotation_1.Body)()),
|
|
214
|
+
__param(6, (0, annotation_1.Header)('x-probe')),
|
|
215
|
+
__param(7, (0, annotation_1.Header)()),
|
|
216
|
+
__metadata("design:type", Function),
|
|
217
|
+
__metadata("design:paramtypes", [String, Object, String, Object, String, Object, String, Object]),
|
|
218
|
+
__metadata("design:returntype", void 0)
|
|
219
|
+
], Args.prototype, "all", null);
|
|
220
|
+
Args = __decorate([
|
|
221
|
+
(0, annotation_1.Controller)('args')
|
|
222
|
+
], Args);
|
|
223
|
+
const f = await serve();
|
|
224
|
+
const res = await f('/args/1/2?q=x&r=y', { method: 'POST', headers: { ...JSON_HEADERS, 'x-probe': 'p' }, body: JSON.stringify({ name: 'n', n: 1 }) });
|
|
225
|
+
(0, chai_1.expect)(res.status).to.equal(200);
|
|
226
|
+
(0, chai_1.expect)(await res.json()).to.deep.equal({
|
|
227
|
+
a: '1', params: { a: '1', b: '2' }, q: 'x', query: { q: 'x', r: 'y' },
|
|
228
|
+
name: 'n', body: { name: 'n', n: 1 }, probe: 'p', hasHost: true,
|
|
229
|
+
});
|
|
230
|
+
(0, chai_1.expect)(Args).to.be.a('function');
|
|
231
|
+
});
|
|
232
|
+
(0, bun_test_1.it)('请求体:JSON、表单(urlencoded,支持嵌套)、纯文本', async () => {
|
|
233
|
+
let BodyCtl = class BodyCtl {
|
|
234
|
+
echo(body) { return { body }; }
|
|
235
|
+
};
|
|
236
|
+
__decorate([
|
|
237
|
+
(0, annotation_1.Post)(),
|
|
238
|
+
__param(0, (0, annotation_1.Body)()),
|
|
239
|
+
__metadata("design:type", Function),
|
|
240
|
+
__metadata("design:paramtypes", [Object]),
|
|
241
|
+
__metadata("design:returntype", void 0)
|
|
242
|
+
], BodyCtl.prototype, "echo", null);
|
|
243
|
+
BodyCtl = __decorate([
|
|
244
|
+
(0, annotation_1.Controller)('body')
|
|
245
|
+
], BodyCtl);
|
|
246
|
+
const f = await serve();
|
|
247
|
+
(0, chai_1.expect)(await (await f('/body', { method: 'POST', headers: JSON_HEADERS, body: '{"x":[1,2]}' })).json()).to.deep.equal({ body: { x: [1, 2] } });
|
|
248
|
+
const form = await f('/body', { method: 'POST', headers: { 'content-type': 'application/x-www-form-urlencoded' }, body: 'a=1&b[c]=2' });
|
|
249
|
+
(0, chai_1.expect)(await form.json()).to.deep.equal({ body: { a: '1', b: { c: '2' } } });
|
|
250
|
+
const text = await f('/body', { method: 'POST', headers: { 'content-type': 'text/plain' }, body: 'hello' });
|
|
251
|
+
(0, chai_1.expect)(await text.json()).to.deep.equal({ body: 'hello' });
|
|
252
|
+
(0, chai_1.expect)(BodyCtl).to.be.a('function');
|
|
253
|
+
});
|
|
254
|
+
(0, bun_test_1.it)('现状:非法 JSON 请求体返回 500(body-parser 标的 400 没被采用),处理函数不会被调用', async () => {
|
|
255
|
+
let called = false;
|
|
256
|
+
let Bad = class Bad {
|
|
257
|
+
take() { called = true; return 1; }
|
|
258
|
+
};
|
|
259
|
+
__decorate([
|
|
260
|
+
(0, annotation_1.Post)(),
|
|
261
|
+
__metadata("design:type", Function),
|
|
262
|
+
__metadata("design:paramtypes", []),
|
|
263
|
+
__metadata("design:returntype", void 0)
|
|
264
|
+
], Bad.prototype, "take", null);
|
|
265
|
+
Bad = __decorate([
|
|
266
|
+
(0, annotation_1.Controller)('bad')
|
|
267
|
+
], Bad);
|
|
268
|
+
const f = await serve();
|
|
269
|
+
const res = await f('/bad', { method: 'POST', headers: JSON_HEADERS, body: '{oops' });
|
|
270
|
+
(0, chai_1.expect)(res.status).to.equal(500);
|
|
271
|
+
(0, chai_1.expect)(await res.text()).to.not.match(/\n\s+at /);
|
|
272
|
+
(0, chai_1.expect)(called).to.equal(false);
|
|
273
|
+
(0, chai_1.expect)(Bad).to.be.a('function');
|
|
274
|
+
});
|
|
275
|
+
bun_test_1.it.todo('期望:请求体解析失败(body-parser 的 err.status 为 4xx)时返回对应的 4xx,而不是 500', () => { });
|
|
276
|
+
(0, bun_test_1.it)('@Req / @Res 拿到原始请求和响应', async () => {
|
|
277
|
+
let Raw = class Raw {
|
|
278
|
+
raw(req, res) {
|
|
279
|
+
res.setHeader('x-from-res', 'yes');
|
|
280
|
+
return `${req.method} ${req.path}`;
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
__decorate([
|
|
284
|
+
(0, annotation_1.Get)(),
|
|
285
|
+
(0, annotation_1.Text)(),
|
|
286
|
+
__param(0, (0, annotation_1.Req)()),
|
|
287
|
+
__param(1, (0, annotation_1.Res)()),
|
|
288
|
+
__metadata("design:type", Function),
|
|
289
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
290
|
+
__metadata("design:returntype", void 0)
|
|
291
|
+
], Raw.prototype, "raw", null);
|
|
292
|
+
Raw = __decorate([
|
|
293
|
+
(0, annotation_1.Controller)('raw')
|
|
294
|
+
], Raw);
|
|
295
|
+
const f = await serve();
|
|
296
|
+
const res = await f('/raw');
|
|
297
|
+
(0, chai_1.expect)(res.headers.get('x-from-res')).to.equal('yes');
|
|
298
|
+
(0, chai_1.expect)(await res.text()).to.equal('GET /raw');
|
|
299
|
+
(0, chai_1.expect)(Raw).to.be.a('function');
|
|
300
|
+
});
|
|
301
|
+
(0, bun_test_1.it)('@Cookie 读请求 cookie;@Cookie(name, value) 在响应里设置 cookie', async () => {
|
|
302
|
+
var _a;
|
|
303
|
+
let CookieCtl = class CookieCtl {
|
|
304
|
+
read(who) { return { who: who !== null && who !== void 0 ? who : null }; }
|
|
305
|
+
write() { return 'ok'; }
|
|
306
|
+
};
|
|
307
|
+
__decorate([
|
|
308
|
+
(0, annotation_1.Get)('read'),
|
|
309
|
+
__param(0, (0, annotation_1.Cookie)('who')),
|
|
310
|
+
__metadata("design:type", Function),
|
|
311
|
+
__metadata("design:paramtypes", [String]),
|
|
312
|
+
__metadata("design:returntype", void 0)
|
|
313
|
+
], CookieCtl.prototype, "read", null);
|
|
314
|
+
__decorate([
|
|
315
|
+
(0, annotation_1.Get)('write'),
|
|
316
|
+
(0, annotation_1.Cookie)('flavor', 'oat'),
|
|
317
|
+
__metadata("design:type", Function),
|
|
318
|
+
__metadata("design:paramtypes", []),
|
|
319
|
+
__metadata("design:returntype", void 0)
|
|
320
|
+
], CookieCtl.prototype, "write", null);
|
|
321
|
+
CookieCtl = __decorate([
|
|
322
|
+
(0, annotation_1.Controller)('cookie')
|
|
323
|
+
], CookieCtl);
|
|
324
|
+
const f = await serve();
|
|
325
|
+
(0, chai_1.expect)(await (await f('/cookie/read', { headers: { cookie: 'who=me' } })).json()).to.deep.equal({ who: 'me' });
|
|
326
|
+
const set = (_a = (await f('/cookie/write')).headers.get('set-cookie')) !== null && _a !== void 0 ? _a : '';
|
|
327
|
+
(0, chai_1.expect)(set).to.match(/flavor=oat/);
|
|
328
|
+
(0, chai_1.expect)(CookieCtl).to.be.a('function');
|
|
329
|
+
});
|
|
330
|
+
(0, bun_test_1.it)('@Session:写入的值在同一会话的下一次请求里能读到', async () => {
|
|
331
|
+
var _a, _b;
|
|
332
|
+
var _c, _d;
|
|
333
|
+
let SessionCtl = class SessionCtl {
|
|
334
|
+
set() { return 'set'; }
|
|
335
|
+
get(step) { return { step: step !== null && step !== void 0 ? step : null }; }
|
|
336
|
+
};
|
|
337
|
+
__decorate([
|
|
338
|
+
(0, annotation_1.Get)('set'),
|
|
339
|
+
(0, annotation_1.Session)('step', 'two'),
|
|
340
|
+
__metadata("design:type", Function),
|
|
341
|
+
__metadata("design:paramtypes", []),
|
|
342
|
+
__metadata("design:returntype", void 0)
|
|
343
|
+
], SessionCtl.prototype, "set", null);
|
|
344
|
+
__decorate([
|
|
345
|
+
(0, annotation_1.Get)('get'),
|
|
346
|
+
__param(0, (0, annotation_1.Session)('step')),
|
|
347
|
+
__metadata("design:type", Function),
|
|
348
|
+
__metadata("design:paramtypes", [String]),
|
|
349
|
+
__metadata("design:returntype", void 0)
|
|
350
|
+
], SessionCtl.prototype, "get", null);
|
|
351
|
+
SessionCtl = __decorate([
|
|
352
|
+
(0, annotation_1.Controller)('session')
|
|
353
|
+
], SessionCtl);
|
|
354
|
+
const f = await serve();
|
|
355
|
+
const first = await f('/session/set');
|
|
356
|
+
const cookies = ((_c = (_b = (_a = first.headers).getSetCookie) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : [(_d = first.headers.get('set-cookie')) !== null && _d !== void 0 ? _d : ''])
|
|
357
|
+
.map(c => c.split(';')[0]).filter(Boolean).join('; ');
|
|
358
|
+
(0, chai_1.expect)(cookies).to.not.equal('');
|
|
359
|
+
(0, chai_1.expect)(await (await f('/session/get', { headers: { cookie: cookies } })).json()).to.deep.equal({ step: 'two' });
|
|
360
|
+
(0, chai_1.expect)(await (await f('/session/get')).json()).to.deep.equal({ step: null });
|
|
361
|
+
(0, chai_1.expect)(SessionCtl).to.be.a('function');
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
(0, bun_test_1.describe)('mvc 响应', () => {
|
|
365
|
+
(0, bun_test_1.it)('默认 JSON 视图;@Text 输出文本;@Json 显式 JSON;内容类型正确', async () => {
|
|
366
|
+
let Views = class Views {
|
|
367
|
+
dflt() { return { ok: true }; }
|
|
368
|
+
text() { return 'plain'; }
|
|
369
|
+
json() { return [1, 2]; }
|
|
370
|
+
};
|
|
371
|
+
__decorate([
|
|
372
|
+
(0, annotation_1.Get)('default'),
|
|
373
|
+
__metadata("design:type", Function),
|
|
374
|
+
__metadata("design:paramtypes", []),
|
|
375
|
+
__metadata("design:returntype", void 0)
|
|
376
|
+
], Views.prototype, "dflt", null);
|
|
377
|
+
__decorate([
|
|
378
|
+
(0, annotation_1.Get)('text'),
|
|
379
|
+
(0, annotation_1.Text)(),
|
|
380
|
+
__metadata("design:type", Function),
|
|
381
|
+
__metadata("design:paramtypes", []),
|
|
382
|
+
__metadata("design:returntype", void 0)
|
|
383
|
+
], Views.prototype, "text", null);
|
|
384
|
+
__decorate([
|
|
385
|
+
(0, annotation_1.Get)('json'),
|
|
386
|
+
(0, annotation_1.Json)(),
|
|
387
|
+
__metadata("design:type", Function),
|
|
388
|
+
__metadata("design:paramtypes", []),
|
|
389
|
+
__metadata("design:returntype", void 0)
|
|
390
|
+
], Views.prototype, "json", null);
|
|
391
|
+
Views = __decorate([
|
|
392
|
+
(0, annotation_1.Controller)('views')
|
|
393
|
+
], Views);
|
|
394
|
+
const f = await serve();
|
|
395
|
+
const d = await f('/views/default');
|
|
396
|
+
(0, chai_1.expect)(d.headers.get('content-type')).to.match(/application\/json/);
|
|
397
|
+
(0, chai_1.expect)(await d.json()).to.deep.equal({ ok: true });
|
|
398
|
+
const t = await f('/views/text');
|
|
399
|
+
(0, chai_1.expect)(t.headers.get('content-type')).to.match(/text\/plain/);
|
|
400
|
+
(0, chai_1.expect)(await t.text()).to.equal('plain');
|
|
401
|
+
(0, chai_1.expect)(await (await f('/views/json')).json()).to.deep.equal([1, 2]);
|
|
402
|
+
(0, chai_1.expect)(Views).to.be.a('function');
|
|
403
|
+
});
|
|
404
|
+
(0, bun_test_1.it)('@Header(name, value) 设置响应头;async 处理函数的返回值同样生效', async () => {
|
|
405
|
+
let Hdr = class Hdr {
|
|
406
|
+
async get() {
|
|
407
|
+
await new Promise(r => setImmediate(r));
|
|
408
|
+
return { late: true };
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
__decorate([
|
|
412
|
+
(0, annotation_1.Get)(),
|
|
413
|
+
(0, annotation_1.Header)('x-powered', 'cell'),
|
|
414
|
+
__metadata("design:type", Function),
|
|
415
|
+
__metadata("design:paramtypes", []),
|
|
416
|
+
__metadata("design:returntype", Promise)
|
|
417
|
+
], Hdr.prototype, "get", null);
|
|
418
|
+
Hdr = __decorate([
|
|
419
|
+
(0, annotation_1.Controller)('hdr')
|
|
420
|
+
], Hdr);
|
|
421
|
+
const f = await serve();
|
|
422
|
+
const res = await f('/hdr');
|
|
423
|
+
(0, chai_1.expect)(res.headers.get('x-powered')).to.equal('cell');
|
|
424
|
+
(0, chai_1.expect)(await res.json()).to.deep.equal({ late: true });
|
|
425
|
+
(0, chai_1.expect)(Hdr).to.be.a('function');
|
|
426
|
+
});
|
|
427
|
+
(0, bun_test_1.it)('返回 undefined 时状态 200', async () => {
|
|
428
|
+
let Void = class Void {
|
|
429
|
+
remove() { }
|
|
430
|
+
};
|
|
431
|
+
__decorate([
|
|
432
|
+
(0, annotation_1.Delete)(),
|
|
433
|
+
__metadata("design:type", Function),
|
|
434
|
+
__metadata("design:paramtypes", []),
|
|
435
|
+
__metadata("design:returntype", void 0)
|
|
436
|
+
], Void.prototype, "remove", null);
|
|
437
|
+
Void = __decorate([
|
|
438
|
+
(0, annotation_1.Controller)('void')
|
|
439
|
+
], Void);
|
|
440
|
+
const f = await serve();
|
|
441
|
+
const res = await f('/void', { method: 'DELETE' });
|
|
442
|
+
(0, chai_1.expect)(res.status).to.equal(200);
|
|
443
|
+
(0, chai_1.expect)(Void).to.be.a('function');
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
(0, bun_test_1.describe)('mvc 异常', () => {
|
|
447
|
+
(0, bun_test_1.it)('抛 HttpError 子类时用它的状态码(如 NotFoundError → 404),响应体是 JSON 且带错误信息', async () => {
|
|
448
|
+
let Err = class Err {
|
|
449
|
+
nf() { throw new node_1.NotFoundError('no such thing'); }
|
|
450
|
+
teapot() { throw new node_1.HttpError(418, 'teapot'); }
|
|
451
|
+
};
|
|
452
|
+
__decorate([
|
|
453
|
+
(0, annotation_1.Get)('nf'),
|
|
454
|
+
__metadata("design:type", Function),
|
|
455
|
+
__metadata("design:paramtypes", []),
|
|
456
|
+
__metadata("design:returntype", void 0)
|
|
457
|
+
], Err.prototype, "nf", null);
|
|
458
|
+
__decorate([
|
|
459
|
+
(0, annotation_1.Get)('teapot'),
|
|
460
|
+
__metadata("design:type", Function),
|
|
461
|
+
__metadata("design:paramtypes", []),
|
|
462
|
+
__metadata("design:returntype", void 0)
|
|
463
|
+
], Err.prototype, "teapot", null);
|
|
464
|
+
Err = __decorate([
|
|
465
|
+
(0, annotation_1.Controller)('err')
|
|
466
|
+
], Err);
|
|
467
|
+
const f = await serve();
|
|
468
|
+
const nf = await f('/err/nf');
|
|
469
|
+
(0, chai_1.expect)(nf.status).to.equal(404);
|
|
470
|
+
(0, chai_1.expect)(nf.headers.get('content-type')).to.match(/application\/json/);
|
|
471
|
+
(0, chai_1.expect)(await nf.text()).to.contain('no such thing');
|
|
472
|
+
(0, chai_1.expect)((await f('/err/teapot')).status).to.equal(418);
|
|
473
|
+
(0, chai_1.expect)(Err).to.be.a('function');
|
|
474
|
+
});
|
|
475
|
+
(0, bun_test_1.it)('抛普通 Error 时返回 500,应用继续服务后续请求', async () => {
|
|
476
|
+
let Boom = class Boom {
|
|
477
|
+
boom() { throw new Error('kaboom'); }
|
|
478
|
+
ok() { return 'fine'; }
|
|
479
|
+
};
|
|
480
|
+
__decorate([
|
|
481
|
+
(0, annotation_1.Get)(),
|
|
482
|
+
__metadata("design:type", Function),
|
|
483
|
+
__metadata("design:paramtypes", []),
|
|
484
|
+
__metadata("design:returntype", void 0)
|
|
485
|
+
], Boom.prototype, "boom", null);
|
|
486
|
+
__decorate([
|
|
487
|
+
(0, annotation_1.Get)('ok'),
|
|
488
|
+
__metadata("design:type", Function),
|
|
489
|
+
__metadata("design:paramtypes", []),
|
|
490
|
+
__metadata("design:returntype", void 0)
|
|
491
|
+
], Boom.prototype, "ok", null);
|
|
492
|
+
Boom = __decorate([
|
|
493
|
+
(0, annotation_1.Controller)('boom')
|
|
494
|
+
], Boom);
|
|
495
|
+
const f = await serve();
|
|
496
|
+
const res = await f('/boom');
|
|
497
|
+
(0, chai_1.expect)(res.status).to.equal(500);
|
|
498
|
+
// 响应体不带调用栈
|
|
499
|
+
(0, chai_1.expect)(await res.text()).to.not.match(/\n\s+at /);
|
|
500
|
+
(0, chai_1.expect)(await (await f('/boom/ok')).json()).to.equal('fine');
|
|
501
|
+
(0, chai_1.expect)(Boom).to.be.a('function');
|
|
502
|
+
});
|
|
503
|
+
(0, bun_test_1.it)('@Catch:控制器里声明的异常处理方法接管匹配类型的错误', async () => {
|
|
504
|
+
class QuotaError extends Error {
|
|
505
|
+
}
|
|
506
|
+
let Catching = class Catching {
|
|
507
|
+
run() { throw new QuotaError('over quota'); }
|
|
508
|
+
other() { throw new Error('other'); }
|
|
509
|
+
onQuota(err) { return `handled: ${err.message}`; }
|
|
510
|
+
};
|
|
511
|
+
__decorate([
|
|
512
|
+
(0, annotation_1.Get)(),
|
|
513
|
+
__metadata("design:type", Function),
|
|
514
|
+
__metadata("design:paramtypes", []),
|
|
515
|
+
__metadata("design:returntype", void 0)
|
|
516
|
+
], Catching.prototype, "run", null);
|
|
517
|
+
__decorate([
|
|
518
|
+
(0, annotation_1.Get)('other'),
|
|
519
|
+
__metadata("design:type", Function),
|
|
520
|
+
__metadata("design:paramtypes", []),
|
|
521
|
+
__metadata("design:returntype", void 0)
|
|
522
|
+
], Catching.prototype, "other", null);
|
|
523
|
+
__decorate([
|
|
524
|
+
(0, annotation_1.Catch)(QuotaError),
|
|
525
|
+
(0, annotation_1.Text)(),
|
|
526
|
+
__metadata("design:type", Function),
|
|
527
|
+
__metadata("design:paramtypes", [QuotaError]),
|
|
528
|
+
__metadata("design:returntype", void 0)
|
|
529
|
+
], Catching.prototype, "onQuota", null);
|
|
530
|
+
Catching = __decorate([
|
|
531
|
+
(0, annotation_1.Controller)('catch')
|
|
532
|
+
], Catching);
|
|
533
|
+
const f = await serve();
|
|
534
|
+
const res = await f('/catch');
|
|
535
|
+
(0, chai_1.expect)(await res.text()).to.equal('handled: over quota');
|
|
536
|
+
(0, chai_1.expect)((await f('/catch/other')).status).to.equal(500);
|
|
537
|
+
(0, chai_1.expect)(Catching).to.be.a('function');
|
|
538
|
+
});
|
|
539
|
+
});
|
|
540
|
+
//# sourceMappingURL=mvc-http.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mvc-http.spec.js","sourceRoot":"","sources":["../../src/node/mvc-http.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uCAAmD;AACnD,+BAA8B;AAC9B,yCAAiD;AACjD,6CAA4C;AAE5C,0FAA0F;AAC1F,oGAAoG;AACpG,kCAAkC;AAClC,0FAAqE;AACrE,wFAAiE;AACjE,2EAA4D;AAC5D,yEAAwD;AACxD,sDAAqC;AACrC,2FAAuF;AACvF,6FAAyF;AACzF,2EAAuE;AACvE,yDAA4D;AAC5D,mGAAuF;AACvF,+CAAqF;AACrF,6CAEsB;AAEtB;;;;;;;GAOG;AACH,MAAM,OAAO,GAAG,IAAA,2BAAa,EAAC,OAAO,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAEtF,MAAM,cAAc,GAAG;IACnB,IAAI,EAAE;QACF,gBAAgB;QAChB,IAAI,EAAE,gBAAgB,EAAE,UAAU,EAAE,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,MAAM,EA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IAAA,iBAAI,GAAE;;6CACM,UAAU;;+CAAuC;QAP5D,QAAQ;YADb,IAAA,uBAAU,EAAC,OAAO,CAAC;WACd,QAAQ,CAQb;QACD,MAAM,CAAC,GAAG,MAAM,KAAK,EAAE,CAAC;QACxB,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC;QAC9B,IAAA,aAAM,EAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACzD,IAAA,aAAM,EAAC,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvD,IAAA,aAAM,EAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -15,7 +15,7 @@ const view_protocol_1 = require("./view-protocol");
|
|
|
15
15
|
const http_1 = require("@celljs/http");
|
|
16
16
|
const node_1 = require("@celljs/web/lib/node");
|
|
17
17
|
const file_1 = require("../annotation/file");
|
|
18
|
-
const
|
|
18
|
+
const node_fs_1 = require("node:fs");
|
|
19
19
|
const path_1 = require("path");
|
|
20
20
|
let FileView = class FileView {
|
|
21
21
|
constructor() {
|
|
@@ -28,7 +28,7 @@ let FileView = class FileView {
|
|
|
28
28
|
}
|
|
29
29
|
async render(model, { metadata }) {
|
|
30
30
|
if (metadata === null || metadata === void 0 ? void 0 : metadata.file) {
|
|
31
|
-
model = (0,
|
|
31
|
+
model = (0, node_fs_1.createReadStream)((0, path_1.join)(__dirname, this.baseFileDir, metadata.file));
|
|
32
32
|
}
|
|
33
33
|
const response = node_1.Context.getCurrent().response;
|
|
34
34
|
if (this.isStream(model)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-view.js","sourceRoot":"","sources":["../../../src/node/view/file-view.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAAmE;AACnE,mDAAuC;AACvC,uCAAkE;AAClE,+CAAyD;AAEzD,6CAAoD;AAEpD,
|
|
1
|
+
{"version":3,"file":"file-view.js","sourceRoot":"","sources":["../../../src/node/view/file-view.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAAmE;AACnE,mDAAuC;AACvC,uCAAkE;AAClE,+CAAyD;AAEzD,6CAAoD;AAEpD,qCAA2C;AAC3C,+BAA4B;AAGrB,IAAM,QAAQ,GAAd,MAAM,QAAQ;IAAd;QAEM,gBAAW,GAAG,gBAAS,CAAC,wBAAwB,CAAC;QAEjD,aAAQ,GAAG,GAAG,CAAC;IAoD5B,CAAC;IA5Ca,QAAQ,CAAC,KAAU;QACzB,OAAO,OAAO,KAAK,KAAK,QAAQ;eACzB,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAU,EAAE,EAAE,QAAQ,EAAgB;QAC/C,IAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,EAAE,CAAC;YACjB,KAAK,GAAG,IAAA,0BAAgB,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;QAC/E,CAAC;QACD,MAAM,QAAQ,GAAG,cAAO,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC;QAC/C,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,cAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAC7B,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QACzC,CAAC;aAAM,CAAC;YACJ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzB,QAAQ,CAAC,SAA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AQ;IADpB,IAAA,gBAAS,EAAC,oBAAI,CAAC;GACH,QAAQ,CAwDpB"}
|
|
@@ -18,7 +18,7 @@ const view_protocol_1 = require("./view-protocol");
|
|
|
18
18
|
const node_1 = require("@celljs/web/lib/node");
|
|
19
19
|
const mustache_1 = __importDefault(require("mustache"));
|
|
20
20
|
const path_1 = require("path");
|
|
21
|
-
const
|
|
21
|
+
const promises_1 = require("node:fs/promises");
|
|
22
22
|
const html_1 = require("../annotation/html");
|
|
23
23
|
const http_1 = require("@celljs/http");
|
|
24
24
|
let HtmlView = class HtmlView {
|
|
@@ -29,7 +29,7 @@ let HtmlView = class HtmlView {
|
|
|
29
29
|
async render(model, { metadata }) {
|
|
30
30
|
const response = node_1.Context.getCurrent().response;
|
|
31
31
|
const { baseViewDir, cache } = this.options;
|
|
32
|
-
const template = await (0,
|
|
32
|
+
const template = await (0, promises_1.readFile)((0, path_1.join)(__dirname, baseViewDir, metadata.file), { encoding: 'utf8' });
|
|
33
33
|
if (cache) {
|
|
34
34
|
mustache_1.default.parse(template);
|
|
35
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-view.js","sourceRoot":"","sources":["../../../src/node/view/html-view.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAAgD;AAChD,mDAAuC;AACvC,+CAA+C;AAC/C,wDAAgC;AAChC,+BAA4B;AAC5B
|
|
1
|
+
{"version":3,"file":"html-view.js","sourceRoot":"","sources":["../../../src/node/view/html-view.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAAgD;AAChD,mDAAuC;AACvC,+CAA+C;AAC/C,wDAAgC;AAChC,+BAA4B;AAC5B,+CAA4C;AAE5C,6CAAoD;AACpD,uCAAyC;AAGlC,IAAM,QAAQ,GAAd,MAAM,QAAQ;IAAd;QAEM,gBAAW,GAAG,gBAAS,CAAC,SAAS,CAAC;QAElC,aAAQ,GAAG,GAAG,CAAC;IAkB5B,CAAC;IAbG,KAAK,CAAC,MAAM,CAAC,KAAU,EAAE,EAAE,QAAQ,EAAgB;QAC/C,MAAM,QAAQ,GAAG,cAAO,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC;QAC/C,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5C,MAAM,QAAQ,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,WAAW,EAAE,QAAS,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QACpG,IAAI,KAAK,EAAE,CAAC;YACR,kBAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC7B,CAAC;QACD,QAAQ,CAAC,IAAI,GAAG,kBAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAgB;;QACxC,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,KAAK,qBAAc,KAAI,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,0CAAE,QAAQ,CAAC,WAAW,CAAC,CAAA,CAAC,CAAC;IACjG,CAAC;CACJ,CAAA;;AAfsB;IADlB,IAAA,YAAK,EAAC,eAAe,CAAC;;yCACS;mBAPvB,QAAQ;IADpB,IAAA,gBAAS,EAAC,oBAAI,CAAC;GACH,QAAQ,CAsBpB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/mvc",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cell-component"
|
|
@@ -29,13 +29,10 @@
|
|
|
29
29
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@celljs/core": "
|
|
33
|
-
"@celljs/http": "
|
|
34
|
-
"@celljs/web": "
|
|
35
|
-
"
|
|
36
|
-
"mustache": "^4.2.0",
|
|
37
|
-
"reflect-metadata": "^0.1.13",
|
|
38
|
-
"tslib": "^2.8.0"
|
|
32
|
+
"@celljs/core": "4.1.0",
|
|
33
|
+
"@celljs/http": "4.1.0",
|
|
34
|
+
"@celljs/web": "4.1.0",
|
|
35
|
+
"mustache": "^4.2.0"
|
|
39
36
|
},
|
|
40
37
|
"devDependencies": {
|
|
41
38
|
"@types/mustache": "^4.2.2"
|
|
@@ -45,56 +42,53 @@
|
|
|
45
42
|
},
|
|
46
43
|
"exports": {
|
|
47
44
|
".": {
|
|
48
|
-
"webpack": "./lib/common/index.js",
|
|
49
45
|
"import": "./esm/common/index.js",
|
|
50
46
|
"default": "./lib/common/index.js"
|
|
51
47
|
},
|
|
52
48
|
"./package.json": "./package.json",
|
|
53
49
|
"./lib/common": {
|
|
54
|
-
"webpack": "./lib/common/index.js",
|
|
55
50
|
"import": "./esm/common/index.js",
|
|
56
51
|
"default": "./lib/common/index.js"
|
|
57
52
|
},
|
|
58
53
|
"./lib/node": {
|
|
59
|
-
"webpack": "./lib/node/index.js",
|
|
60
54
|
"import": "./esm/node/index.js",
|
|
61
55
|
"default": "./lib/node/index.js"
|
|
62
56
|
},
|
|
63
57
|
"./lib/node/annotation": {
|
|
64
|
-
"webpack": "./lib/node/annotation/index.js",
|
|
65
58
|
"import": "./esm/node/annotation/index.js",
|
|
66
59
|
"default": "./lib/node/annotation/index.js"
|
|
67
60
|
},
|
|
68
61
|
"./lib/node/error": {
|
|
69
|
-
"webpack": "./lib/node/error/index.js",
|
|
70
62
|
"import": "./esm/node/error/index.js",
|
|
71
63
|
"default": "./lib/node/error/index.js"
|
|
72
64
|
},
|
|
73
65
|
"./lib/node/handler": {
|
|
74
|
-
"webpack": "./lib/node/handler/index.js",
|
|
75
66
|
"import": "./esm/node/handler/index.js",
|
|
76
67
|
"default": "./lib/node/handler/index.js"
|
|
77
68
|
},
|
|
78
69
|
"./lib/node/resolver": {
|
|
79
|
-
"webpack": "./lib/node/resolver/index.js",
|
|
80
70
|
"import": "./esm/node/resolver/index.js",
|
|
81
71
|
"default": "./lib/node/resolver/index.js"
|
|
82
72
|
},
|
|
83
73
|
"./lib/node/view": {
|
|
84
|
-
"webpack": "./lib/node/view/index.js",
|
|
85
74
|
"import": "./esm/node/view/index.js",
|
|
86
75
|
"default": "./lib/node/view/index.js"
|
|
87
76
|
},
|
|
88
77
|
"./lib/*.js": {
|
|
89
|
-
"webpack": "./lib/*.js",
|
|
90
78
|
"import": "./esm/*.js",
|
|
91
79
|
"default": "./lib/*.js"
|
|
92
80
|
},
|
|
93
81
|
"./lib/*": {
|
|
94
|
-
"webpack": "./lib/*.js",
|
|
95
82
|
"import": "./esm/*.js",
|
|
96
83
|
"default": "./lib/*.js"
|
|
97
84
|
},
|
|
98
85
|
"./*": "./*"
|
|
86
|
+
},
|
|
87
|
+
"cell": {
|
|
88
|
+
"modules": {
|
|
89
|
+
"backend": [
|
|
90
|
+
"lib/node/module"
|
|
91
|
+
]
|
|
92
|
+
}
|
|
99
93
|
}
|
|
100
94
|
}
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { describe, it, afterEach } from 'bun:test';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { createServer, Server } from 'node:http';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import { AddressInfo } from 'node:net';
|
|
6
|
+
// 按 CLI 生成的后端入口加载顺序导入:core 的 static module → web 的 module → mvc 的 module(见 @celljs/vite 的
|
|
7
|
+
// ContainerGenerator 与各包 package.json 的 cell 字段)。不要导入 application-factory:它会顺带登记 CommonApplication,
|
|
8
|
+
// 和 node 的 BackendApplication 冲突。
|
|
9
|
+
import coreCommonStatic from '@celljs/core/lib/common/static-module';
|
|
10
|
+
import coreNodeStatic from '@celljs/core/lib/node/static-module';
|
|
11
|
+
import webCommonModule from '@celljs/web/lib/common/module';
|
|
12
|
+
import webNodeModule from '@celljs/web/lib/node/module';
|
|
13
|
+
import mvcNodeModule from './module';
|
|
14
|
+
import { ContainerFactory } from '@celljs/core/lib/common/container/container-factory';
|
|
15
|
+
import { ContainerProvider } from '@celljs/core/lib/common/container/container-provider';
|
|
16
|
+
import { autoBind } from '@celljs/core/lib/common/container/auto-bind';
|
|
17
|
+
import { currentThis } from '@celljs/core/lib/common/utils';
|
|
18
|
+
import { Application } from '@celljs/core/lib/common/application/application-protocol';
|
|
19
|
+
import { Context, Dispatcher, NotFoundError, HttpError } from '@celljs/web/lib/node';
|
|
20
|
+
import {
|
|
21
|
+
Controller, Get, Post, Put, Delete, Patch, All, Param, Query, Body, Header, Cookie, Session, Req, Res, Text, Json, Catch
|
|
22
|
+
} from './annotation';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* mvc 的 HTTP 行为约定(阶段 1.E 行为测试):经真实 HTTP 请求断言路由、参数解析、响应与异常。
|
|
26
|
+
*
|
|
27
|
+
* 请求路径与 express-adapter 的 http-application-entry 相同:express 收到请求 → new Context(req, res) →
|
|
28
|
+
* Context.run → Dispatcher.dispatch。express 是 @celljs/web 的依赖,这里从 web 的位置解析,mvc 不新增依赖。
|
|
29
|
+
* 配置是 core / web / mvc / http 的 cell.yml 合并后的默认值(CLI 会做这一步;这里照抄,保持与 cell.yml 一致)。
|
|
30
|
+
* 阶段 2 换 HTTP 管线时,只需要替换 serve(),用例本身不用改。
|
|
31
|
+
*/
|
|
32
|
+
const express = createRequire(require.resolve('@celljs/web/package.json'))('express');
|
|
33
|
+
|
|
34
|
+
const DEFAULT_CONFIG = {
|
|
35
|
+
cell: {
|
|
36
|
+
// core/cell.yml
|
|
37
|
+
name: 'Cell Framework', annotation: { Component: { proxy: false } }, aop: { enabled: true }, logger: { level: 'error' }, tenant: { enabled: false },
|
|
38
|
+
// web/cell.yml(含 backend 段)
|
|
39
|
+
session: { autoCommit: true, maxAge: 86400000, sessionIdKey: 'cell:sessionId', sessionKey: 'cell:session' },
|
|
40
|
+
server: { path: '/', port: 3000, host: '127.0.0.1', endpoint: 'http://localhost:${cell.server.port}' },
|
|
41
|
+
trace: { requestField: 'X-Cell-Trace-ID', responseField: 'X-Cell-Trace-ID' },
|
|
42
|
+
health: { url: '/health', method: 'GET' },
|
|
43
|
+
web: { route: { cacheSize: 500 }, validationPipeOptions: { detailedOutputDisabled: false, transformEnabled: true } },
|
|
44
|
+
cookies: { keys: ['abcdef'] },
|
|
45
|
+
// mvc/cell.yml
|
|
46
|
+
mvc: { path: '/*', defaultViewName: 'json', baseFileDir: 'assets' },
|
|
47
|
+
mustache: { cache: false, baseViewDir: 'assets/views' },
|
|
48
|
+
// http/cell.yml
|
|
49
|
+
client: { config: { withCredentials: true, headers: { 'X-Requested-With': 'XMLHttpRequest' } } },
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
let server: Server | undefined;
|
|
54
|
+
afterEach(async () => {
|
|
55
|
+
await new Promise<void>(r => (server ? server.close(() => r()) : r()));
|
|
56
|
+
server = undefined;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/** 启动应用(在调用之前定义好的控制器都会被装配),返回指向它的 fetch。 */
|
|
60
|
+
async function serve(): Promise<(path: string, init?: RequestInit) => Promise<Response>> {
|
|
61
|
+
currentThis.cellProps = structuredClone(DEFAULT_CONFIG);
|
|
62
|
+
const container = ContainerFactory.create(coreCommonStatic, coreNodeStatic, webCommonModule, webNodeModule, mvcNodeModule, autoBind());
|
|
63
|
+
ContainerProvider.set(container);
|
|
64
|
+
const app = container.get<Application>(Application);
|
|
65
|
+
await app.start();
|
|
66
|
+
const handler = express();
|
|
67
|
+
handler.all('*', (req: any, res: any) => {
|
|
68
|
+
const ctx = new Context(req, res);
|
|
69
|
+
Context.run(() => container.get<Dispatcher<Context>>(Dispatcher).dispatch(ctx));
|
|
70
|
+
});
|
|
71
|
+
server = createServer(handler);
|
|
72
|
+
await new Promise<void>(r => server!.listen(0, '127.0.0.1', r));
|
|
73
|
+
const base = `http://127.0.0.1:${(server!.address() as AddressInfo).port}`;
|
|
74
|
+
return (path, init) => fetch(base + path, init);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const JSON_HEADERS = { 'content-type': 'application/json' };
|
|
78
|
+
|
|
79
|
+
describe('mvc 路由', () => {
|
|
80
|
+
|
|
81
|
+
it('按控制器前缀 + 方法路径匹配;HTTP 方法不同走不同处理函数', async () => {
|
|
82
|
+
@Controller('items')
|
|
83
|
+
class Items {
|
|
84
|
+
@Get()
|
|
85
|
+
list() { return ['a', 'b']; }
|
|
86
|
+
@Get(':id')
|
|
87
|
+
one(@Param('id') id: string) { return { id }; }
|
|
88
|
+
@Post()
|
|
89
|
+
create() { return 'created'; }
|
|
90
|
+
@Put(':id')
|
|
91
|
+
replace(@Param('id') id: string) { return `put ${id}`; }
|
|
92
|
+
@Patch(':id')
|
|
93
|
+
patch(@Param('id') id: string) { return `patch ${id}`; }
|
|
94
|
+
@Delete(':id')
|
|
95
|
+
remove(@Param('id') id: string) { return `deleted ${id}`; }
|
|
96
|
+
}
|
|
97
|
+
const f = await serve();
|
|
98
|
+
expect(await (await f('/items')).json()).to.deep.equal(['a', 'b']);
|
|
99
|
+
expect(await (await f('/items/42')).json()).to.deep.equal({ id: '42' });
|
|
100
|
+
expect(await (await f('/items', { method: 'POST' })).json()).to.equal('created');
|
|
101
|
+
expect(await (await f('/items/1', { method: 'PUT' })).json()).to.equal('put 1');
|
|
102
|
+
expect(await (await f('/items/1', { method: 'PATCH' })).json()).to.equal('patch 1');
|
|
103
|
+
expect(await (await f('/items/1', { method: 'DELETE' })).json()).to.equal('deleted 1');
|
|
104
|
+
expect(Items).to.be.a('function');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('没有前缀的控制器;@All 匹配所有方法', async () => {
|
|
108
|
+
@Controller()
|
|
109
|
+
class Root {
|
|
110
|
+
@Get()
|
|
111
|
+
@Text()
|
|
112
|
+
home() { return 'home'; }
|
|
113
|
+
@All('any')
|
|
114
|
+
@Text()
|
|
115
|
+
any() { return 'any'; }
|
|
116
|
+
}
|
|
117
|
+
const f = await serve();
|
|
118
|
+
expect(await (await f('/')).text()).to.equal('home');
|
|
119
|
+
for (const method of ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']) {
|
|
120
|
+
expect(await (await f('/any', { method })).text()).to.equal('any');
|
|
121
|
+
}
|
|
122
|
+
expect(Root).to.be.a('function');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('没有匹配的路由返回 404,错误信息里有方法和路径', async () => {
|
|
126
|
+
@Controller('only')
|
|
127
|
+
class Only {
|
|
128
|
+
@Get()
|
|
129
|
+
get() { return 1; }
|
|
130
|
+
}
|
|
131
|
+
const f = await serve();
|
|
132
|
+
const res = await f('/nowhere');
|
|
133
|
+
expect(res.status).to.equal(404);
|
|
134
|
+
expect(await res.text()).to.contain('/nowhere');
|
|
135
|
+
expect((await f('/only', { method: 'POST' })).status).to.equal(404);
|
|
136
|
+
expect(Only).to.be.a('function');
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
describe('mvc 参数解析', () => {
|
|
141
|
+
|
|
142
|
+
it('@Param / @Query / @Body / @Header 取单个值或整体', async () => {
|
|
143
|
+
@Controller('args')
|
|
144
|
+
class Args {
|
|
145
|
+
@Post(':a/:b')
|
|
146
|
+
all(
|
|
147
|
+
@Param('a') a: string, @Param() params: any,
|
|
148
|
+
@Query('q') q: string, @Query() query: any,
|
|
149
|
+
@Body('name') name: string, @Body() body: any,
|
|
150
|
+
@Header('x-probe') probe: string, @Header() headers: any
|
|
151
|
+
) {
|
|
152
|
+
return { a, params, q, query, name, body, probe, hasHost: !!headers.host };
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const f = await serve();
|
|
156
|
+
const res = await f('/args/1/2?q=x&r=y', { method: 'POST', headers: { ...JSON_HEADERS, 'x-probe': 'p' }, body: JSON.stringify({ name: 'n', n: 1 }) });
|
|
157
|
+
expect(res.status).to.equal(200);
|
|
158
|
+
expect(await res.json()).to.deep.equal({
|
|
159
|
+
a: '1', params: { a: '1', b: '2' }, q: 'x', query: { q: 'x', r: 'y' },
|
|
160
|
+
name: 'n', body: { name: 'n', n: 1 }, probe: 'p', hasHost: true,
|
|
161
|
+
});
|
|
162
|
+
expect(Args).to.be.a('function');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('请求体:JSON、表单(urlencoded,支持嵌套)、纯文本', async () => {
|
|
166
|
+
@Controller('body')
|
|
167
|
+
class BodyCtl {
|
|
168
|
+
@Post()
|
|
169
|
+
echo(@Body() body: any) { return { body }; }
|
|
170
|
+
}
|
|
171
|
+
const f = await serve();
|
|
172
|
+
expect(await (await f('/body', { method: 'POST', headers: JSON_HEADERS, body: '{"x":[1,2]}' })).json()).to.deep.equal({ body: { x: [1, 2] } });
|
|
173
|
+
const form = await f('/body', { method: 'POST', headers: { 'content-type': 'application/x-www-form-urlencoded' }, body: 'a=1&b[c]=2' });
|
|
174
|
+
expect(await form.json()).to.deep.equal({ body: { a: '1', b: { c: '2' } } });
|
|
175
|
+
const text = await f('/body', { method: 'POST', headers: { 'content-type': 'text/plain' }, body: 'hello' });
|
|
176
|
+
expect(await text.json()).to.deep.equal({ body: 'hello' });
|
|
177
|
+
expect(BodyCtl).to.be.a('function');
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('现状:非法 JSON 请求体返回 500(body-parser 标的 400 没被采用),处理函数不会被调用', async () => {
|
|
181
|
+
let called = false;
|
|
182
|
+
@Controller('bad')
|
|
183
|
+
class Bad {
|
|
184
|
+
@Post()
|
|
185
|
+
take() { called = true; return 1; }
|
|
186
|
+
}
|
|
187
|
+
const f = await serve();
|
|
188
|
+
const res = await f('/bad', { method: 'POST', headers: JSON_HEADERS, body: '{oops' });
|
|
189
|
+
expect(res.status).to.equal(500);
|
|
190
|
+
expect(await res.text()).to.not.match(/\n\s+at /);
|
|
191
|
+
expect(called).to.equal(false);
|
|
192
|
+
expect(Bad).to.be.a('function');
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it.todo('期望:请求体解析失败(body-parser 的 err.status 为 4xx)时返回对应的 4xx,而不是 500', () => { });
|
|
196
|
+
|
|
197
|
+
it('@Req / @Res 拿到原始请求和响应', async () => {
|
|
198
|
+
@Controller('raw')
|
|
199
|
+
class Raw {
|
|
200
|
+
@Get()
|
|
201
|
+
@Text()
|
|
202
|
+
raw(@Req() req: any, @Res() res: any) {
|
|
203
|
+
res.setHeader('x-from-res', 'yes');
|
|
204
|
+
return `${req.method} ${req.path}`;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const f = await serve();
|
|
208
|
+
const res = await f('/raw');
|
|
209
|
+
expect(res.headers.get('x-from-res')).to.equal('yes');
|
|
210
|
+
expect(await res.text()).to.equal('GET /raw');
|
|
211
|
+
expect(Raw).to.be.a('function');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('@Cookie 读请求 cookie;@Cookie(name, value) 在响应里设置 cookie', async () => {
|
|
215
|
+
@Controller('cookie')
|
|
216
|
+
class CookieCtl {
|
|
217
|
+
@Get('read')
|
|
218
|
+
read(@Cookie('who') who: string) { return { who: who ?? null }; }
|
|
219
|
+
@Get('write')
|
|
220
|
+
@Cookie('flavor', 'oat')
|
|
221
|
+
write() { return 'ok'; }
|
|
222
|
+
}
|
|
223
|
+
const f = await serve();
|
|
224
|
+
expect(await (await f('/cookie/read', { headers: { cookie: 'who=me' } })).json()).to.deep.equal({ who: 'me' });
|
|
225
|
+
const set = (await f('/cookie/write')).headers.get('set-cookie') ?? '';
|
|
226
|
+
expect(set).to.match(/flavor=oat/);
|
|
227
|
+
expect(CookieCtl).to.be.a('function');
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('@Session:写入的值在同一会话的下一次请求里能读到', async () => {
|
|
231
|
+
@Controller('session')
|
|
232
|
+
class SessionCtl {
|
|
233
|
+
@Get('set')
|
|
234
|
+
@Session('step', 'two')
|
|
235
|
+
set() { return 'set'; }
|
|
236
|
+
@Get('get')
|
|
237
|
+
get(@Session('step') step: string) { return { step: step ?? null }; }
|
|
238
|
+
}
|
|
239
|
+
const f = await serve();
|
|
240
|
+
const first = await f('/session/set');
|
|
241
|
+
const cookies = (first.headers.getSetCookie?.() ?? [first.headers.get('set-cookie') ?? ''])
|
|
242
|
+
.map(c => c.split(';')[0]).filter(Boolean).join('; ');
|
|
243
|
+
expect(cookies).to.not.equal('');
|
|
244
|
+
expect(await (await f('/session/get', { headers: { cookie: cookies } })).json()).to.deep.equal({ step: 'two' });
|
|
245
|
+
expect(await (await f('/session/get')).json()).to.deep.equal({ step: null });
|
|
246
|
+
expect(SessionCtl).to.be.a('function');
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe('mvc 响应', () => {
|
|
251
|
+
|
|
252
|
+
it('默认 JSON 视图;@Text 输出文本;@Json 显式 JSON;内容类型正确', async () => {
|
|
253
|
+
@Controller('views')
|
|
254
|
+
class Views {
|
|
255
|
+
@Get('default')
|
|
256
|
+
dflt() { return { ok: true }; }
|
|
257
|
+
@Get('text')
|
|
258
|
+
@Text()
|
|
259
|
+
text() { return 'plain'; }
|
|
260
|
+
@Get('json')
|
|
261
|
+
@Json()
|
|
262
|
+
json() { return [1, 2]; }
|
|
263
|
+
}
|
|
264
|
+
const f = await serve();
|
|
265
|
+
const d = await f('/views/default');
|
|
266
|
+
expect(d.headers.get('content-type')).to.match(/application\/json/);
|
|
267
|
+
expect(await d.json()).to.deep.equal({ ok: true });
|
|
268
|
+
const t = await f('/views/text');
|
|
269
|
+
expect(t.headers.get('content-type')).to.match(/text\/plain/);
|
|
270
|
+
expect(await t.text()).to.equal('plain');
|
|
271
|
+
expect(await (await f('/views/json')).json()).to.deep.equal([1, 2]);
|
|
272
|
+
expect(Views).to.be.a('function');
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it('@Header(name, value) 设置响应头;async 处理函数的返回值同样生效', async () => {
|
|
276
|
+
@Controller('hdr')
|
|
277
|
+
class Hdr {
|
|
278
|
+
@Get()
|
|
279
|
+
@Header('x-powered', 'cell')
|
|
280
|
+
async get() {
|
|
281
|
+
await new Promise(r => setImmediate(r));
|
|
282
|
+
return { late: true };
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const f = await serve();
|
|
286
|
+
const res = await f('/hdr');
|
|
287
|
+
expect(res.headers.get('x-powered')).to.equal('cell');
|
|
288
|
+
expect(await res.json()).to.deep.equal({ late: true });
|
|
289
|
+
expect(Hdr).to.be.a('function');
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('返回 undefined 时状态 200', async () => {
|
|
293
|
+
@Controller('void')
|
|
294
|
+
class Void {
|
|
295
|
+
@Delete()
|
|
296
|
+
remove(): void { }
|
|
297
|
+
}
|
|
298
|
+
const f = await serve();
|
|
299
|
+
const res = await f('/void', { method: 'DELETE' });
|
|
300
|
+
expect(res.status).to.equal(200);
|
|
301
|
+
expect(Void).to.be.a('function');
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
describe('mvc 异常', () => {
|
|
306
|
+
|
|
307
|
+
it('抛 HttpError 子类时用它的状态码(如 NotFoundError → 404),响应体是 JSON 且带错误信息', async () => {
|
|
308
|
+
@Controller('err')
|
|
309
|
+
class Err {
|
|
310
|
+
@Get('nf')
|
|
311
|
+
nf() { throw new NotFoundError('no such thing'); }
|
|
312
|
+
@Get('teapot')
|
|
313
|
+
teapot() { throw new HttpError(418, 'teapot'); }
|
|
314
|
+
}
|
|
315
|
+
const f = await serve();
|
|
316
|
+
const nf = await f('/err/nf');
|
|
317
|
+
expect(nf.status).to.equal(404);
|
|
318
|
+
expect(nf.headers.get('content-type')).to.match(/application\/json/);
|
|
319
|
+
expect(await nf.text()).to.contain('no such thing');
|
|
320
|
+
expect((await f('/err/teapot')).status).to.equal(418);
|
|
321
|
+
expect(Err).to.be.a('function');
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('抛普通 Error 时返回 500,应用继续服务后续请求', async () => {
|
|
325
|
+
@Controller('boom')
|
|
326
|
+
class Boom {
|
|
327
|
+
@Get()
|
|
328
|
+
boom() { throw new Error('kaboom'); }
|
|
329
|
+
@Get('ok')
|
|
330
|
+
ok() { return 'fine'; }
|
|
331
|
+
}
|
|
332
|
+
const f = await serve();
|
|
333
|
+
const res = await f('/boom');
|
|
334
|
+
expect(res.status).to.equal(500);
|
|
335
|
+
// 响应体不带调用栈
|
|
336
|
+
expect(await res.text()).to.not.match(/\n\s+at /);
|
|
337
|
+
expect(await (await f('/boom/ok')).json()).to.equal('fine');
|
|
338
|
+
expect(Boom).to.be.a('function');
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it('@Catch:控制器里声明的异常处理方法接管匹配类型的错误', async () => {
|
|
342
|
+
class QuotaError extends Error { }
|
|
343
|
+
@Controller('catch')
|
|
344
|
+
class Catching {
|
|
345
|
+
@Get()
|
|
346
|
+
run() { throw new QuotaError('over quota'); }
|
|
347
|
+
@Get('other')
|
|
348
|
+
other() { throw new Error('other'); }
|
|
349
|
+
@Catch(QuotaError)
|
|
350
|
+
@Text()
|
|
351
|
+
onQuota(err: QuotaError) { return `handled: ${err.message}`; }
|
|
352
|
+
}
|
|
353
|
+
const f = await serve();
|
|
354
|
+
const res = await f('/catch');
|
|
355
|
+
expect(await res.text()).to.equal('handled: over quota');
|
|
356
|
+
expect((await f('/catch/other')).status).to.equal(500);
|
|
357
|
+
expect(Catching).to.be.a('function');
|
|
358
|
+
});
|
|
359
|
+
});
|
|
@@ -5,7 +5,7 @@ import { Context, Response } from '@celljs/web/lib/node';
|
|
|
5
5
|
import { Stream } from 'stream';
|
|
6
6
|
import { FILE_VIEW_NAME } from '../annotation/file';
|
|
7
7
|
import { ViewMetadata } from '../annotation/view';
|
|
8
|
-
import { createReadStream } from 'fs
|
|
8
|
+
import { createReadStream } from 'node:fs';
|
|
9
9
|
import { join } from 'path';
|
|
10
10
|
|
|
11
11
|
@Component(View)
|
|
@@ -3,7 +3,7 @@ import { View } from './view-protocol';
|
|
|
3
3
|
import { Context } from '@celljs/web/lib/node';
|
|
4
4
|
import Mustache from 'mustache';
|
|
5
5
|
import { join } from 'path';
|
|
6
|
-
import { readFile } from 'fs
|
|
6
|
+
import { readFile } from 'node:fs/promises';
|
|
7
7
|
import { ViewMetadata } from '../annotation/view';
|
|
8
8
|
import { HTML_VIEW_NAME } from '../annotation/html';
|
|
9
9
|
import { MediaType } from '@celljs/http';
|