@domain.js/main 1.0.0 → 1.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/dist/http/index.js +3 -1
- package/dist/http/router.js +29 -4
- package/package.json +3 -1
package/dist/http/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Main = Main;
|
|
7
|
+
const formbody_1 = __importDefault(require("@fastify/formbody"));
|
|
7
8
|
const multipart_1 = __importDefault(require("@fastify/multipart"));
|
|
8
9
|
const fastify_1 = __importDefault(require("fastify"));
|
|
9
10
|
const fastify_socket_io_1 = __importDefault(require("fastify-socket.io"));
|
|
@@ -25,6 +26,7 @@ function Main(cnf, deps) {
|
|
|
25
26
|
fileSize: cnf.bodyMaxBytes || 10 * 1024 * 1024, // 参数最大容量 10MB
|
|
26
27
|
},
|
|
27
28
|
});
|
|
29
|
+
server.register(formbody_1.default);
|
|
28
30
|
server.register(fastify_socket_io_1.default, {
|
|
29
31
|
cors: {
|
|
30
32
|
origin: "*",
|
|
@@ -42,7 +44,7 @@ function Main(cnf, deps) {
|
|
|
42
44
|
routers(router);
|
|
43
45
|
// 根据需求起送socket服务
|
|
44
46
|
if (cnf.socket) {
|
|
45
|
-
server.ready((
|
|
47
|
+
server.ready((_err) => {
|
|
46
48
|
const io = server.io;
|
|
47
49
|
// 处理日志
|
|
48
50
|
if (socketLogger) {
|
package/dist/http/router.js
CHANGED
|
@@ -46,12 +46,37 @@ function Router(deps) {
|
|
|
46
46
|
const send = async (res, results, isEventStream = false) => {
|
|
47
47
|
if ((0, utils_1.isStream)(results)) {
|
|
48
48
|
if (isEventStream) {
|
|
49
|
-
res.
|
|
49
|
+
// 告知 Fastify 由我们自行通过 res.raw 发送响应,避免 handler 返回后框架再发一次
|
|
50
|
+
res.hijack();
|
|
51
|
+
// 使用 res.raw 直接写响应时,Fastify 不会把 reply.type/header 同步到 raw,
|
|
52
|
+
// 必须在 Node 原生 response 上设置头,否则 Content-Type 等不会生效。
|
|
53
|
+
res.raw.setHeader("Content-Type", "text/event-stream");
|
|
54
|
+
res.raw.setHeader("Cache-Control", "no-cache");
|
|
55
|
+
res.raw.setHeader("Pragma", "no-cache");
|
|
56
|
+
res.raw.setHeader("Connection", "keep-alive");
|
|
57
|
+
if (typeof res.raw.flushHeaders === "function") {
|
|
58
|
+
res.raw.flushHeaders();
|
|
59
|
+
}
|
|
50
60
|
await new Promise((resolve) => {
|
|
51
|
-
|
|
61
|
+
const onEnd = () => {
|
|
62
|
+
cleanup();
|
|
63
|
+
resolve();
|
|
64
|
+
};
|
|
65
|
+
const onError = () => {
|
|
66
|
+
cleanup();
|
|
67
|
+
resolve();
|
|
68
|
+
};
|
|
69
|
+
const cleanup = () => {
|
|
70
|
+
results.off("data", onData);
|
|
71
|
+
results.off("end", onEnd);
|
|
72
|
+
results.off("error", onError);
|
|
73
|
+
};
|
|
74
|
+
const onData = (chunk) => {
|
|
52
75
|
res.raw.write(chunk);
|
|
53
|
-
}
|
|
54
|
-
results.on("
|
|
76
|
+
};
|
|
77
|
+
results.on("data", onData);
|
|
78
|
+
results.on("end", onEnd);
|
|
79
|
+
results.on("error", onError);
|
|
55
80
|
});
|
|
56
81
|
}
|
|
57
82
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domain.js/main",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "DDD framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@babel/eslint-parser": "^7.28.6",
|
|
31
31
|
"@eslint/js": "^10.0.1",
|
|
32
|
+
"@fastify/formbody": "^8.0.2",
|
|
32
33
|
"@fastify/multipart": "^9.4.0",
|
|
33
34
|
"@types/async": "^3.2.25",
|
|
34
35
|
"@types/jest": "^30.0.0",
|
|
@@ -77,6 +78,7 @@
|
|
|
77
78
|
"xlsx": "^0.18.5"
|
|
78
79
|
},
|
|
79
80
|
"peerDependencies": {
|
|
81
|
+
"@fastify/formbody": "^8.0.2",
|
|
80
82
|
"@fastify/multipart": "^9.4.0",
|
|
81
83
|
"async": "^3.2.6",
|
|
82
84
|
"axios": "^1.13.5",
|