@jayfong/x-server 2.50.1 → 2.51.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/lib/_cjs/core/server.js +31 -0
- package/lib/core/server.d.ts +1 -0
- package/lib/core/server.js +31 -0
- package/package.json +1 -1
package/lib/_cjs/core/server.js
CHANGED
|
@@ -139,6 +139,9 @@ class Server {
|
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
// 静态文件服务
|
|
143
|
+
this.applyStatic();
|
|
144
|
+
|
|
142
145
|
// 接口统一入口
|
|
143
146
|
fastify.route({
|
|
144
147
|
method: 'POST',
|
|
@@ -170,12 +173,40 @@ class Server {
|
|
|
170
173
|
return 'ping:success';
|
|
171
174
|
} else if (payload.type === 'updateEnv') {
|
|
172
175
|
Object.assign(_x.x.env, payload.data);
|
|
176
|
+
|
|
177
|
+
// 更新静态文件服务
|
|
178
|
+
this.applyStatic();
|
|
173
179
|
}
|
|
174
180
|
}
|
|
175
181
|
}
|
|
176
182
|
});
|
|
177
183
|
});
|
|
178
184
|
}
|
|
185
|
+
async applyStatic() {
|
|
186
|
+
if (Array.isArray(_x.x.env.APP_STATIC_CONTENT)) {
|
|
187
|
+
const staticContent = _x.x.env.APP_STATIC_CONTENT;
|
|
188
|
+
for (const item of staticContent) {
|
|
189
|
+
if (!item.method) {
|
|
190
|
+
item.method = 'GET';
|
|
191
|
+
}
|
|
192
|
+
if (!this.fastify.hasRoute({
|
|
193
|
+
method: item.method,
|
|
194
|
+
url: item.path
|
|
195
|
+
})) {
|
|
196
|
+
this.fastify.route({
|
|
197
|
+
method: item.method,
|
|
198
|
+
url: item.path,
|
|
199
|
+
handler: async (_req, res) => {
|
|
200
|
+
if (!item.contentType && typeof item.content === 'string') {
|
|
201
|
+
res.header('Content-Type', 'plain/text');
|
|
202
|
+
}
|
|
203
|
+
return item.content;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
179
210
|
async startCrons() {
|
|
180
211
|
// @ts-ignore
|
|
181
212
|
await Promise.resolve().then(() => (0, _interopRequireWildcard2.default)(require('.x/crons')));
|
package/lib/core/server.d.ts
CHANGED
package/lib/core/server.js
CHANGED
|
@@ -133,6 +133,9 @@ export class Server {
|
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
// 静态文件服务
|
|
137
|
+
this.applyStatic();
|
|
138
|
+
|
|
136
139
|
// 接口统一入口
|
|
137
140
|
fastify.route({
|
|
138
141
|
method: 'POST',
|
|
@@ -164,12 +167,40 @@ export class Server {
|
|
|
164
167
|
return 'ping:success';
|
|
165
168
|
} else if (payload.type === 'updateEnv') {
|
|
166
169
|
Object.assign(x.env, payload.data);
|
|
170
|
+
|
|
171
|
+
// 更新静态文件服务
|
|
172
|
+
this.applyStatic();
|
|
167
173
|
}
|
|
168
174
|
}
|
|
169
175
|
}
|
|
170
176
|
});
|
|
171
177
|
});
|
|
172
178
|
}
|
|
179
|
+
async applyStatic() {
|
|
180
|
+
if (Array.isArray(x.env.APP_STATIC_CONTENT)) {
|
|
181
|
+
const staticContent = x.env.APP_STATIC_CONTENT;
|
|
182
|
+
for (const item of staticContent) {
|
|
183
|
+
if (!item.method) {
|
|
184
|
+
item.method = 'GET';
|
|
185
|
+
}
|
|
186
|
+
if (!this.fastify.hasRoute({
|
|
187
|
+
method: item.method,
|
|
188
|
+
url: item.path
|
|
189
|
+
})) {
|
|
190
|
+
this.fastify.route({
|
|
191
|
+
method: item.method,
|
|
192
|
+
url: item.path,
|
|
193
|
+
handler: async (_req, res) => {
|
|
194
|
+
if (!item.contentType && typeof item.content === 'string') {
|
|
195
|
+
res.header('Content-Type', 'plain/text');
|
|
196
|
+
}
|
|
197
|
+
return item.content;
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
173
204
|
async startCrons() {
|
|
174
205
|
// @ts-ignore
|
|
175
206
|
await import('.x/crons');
|