@jayfong/x-server 2.50.0 → 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.
@@ -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')));
@@ -14,6 +14,7 @@ export declare class Server {
14
14
  private applyServices;
15
15
  private applyPlugins;
16
16
  private applyRoutes;
17
+ private applyStatic;
17
18
  private startCrons;
18
19
  private applyAutoClose;
19
20
  }
@@ -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');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.50.0",
3
+ "version": "2.51.0",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",
@@ -9,13 +9,10 @@
9
9
  "bin": {
10
10
  "xs": "lib/_cjs/cli/cli.js"
11
11
  },
12
- "files": [
13
- "lib"
14
- ],
12
+ "files": ["lib"],
15
13
  "scripts": {
16
14
  "build": "haoma compile",
17
15
  "build_test_pkg": "tyn build && rm -rf ./lib_test && mkdir -p ./lib_test && cp -r ./lib ./lib_test/lib && cp ./package.json ./lib_test/package.json && cd ./tests/app && tyn add file:../../lib_test",
18
- "preinstall": "tnpx only-allow pnpm",
19
16
  "test": "tsc --noEmit -p ./tsconfig.build.json && jest \"$(pwd)/src/\"",
20
17
  "test_all": "tsc --noEmit -p ./tsconfig.build.json && jest",
21
18
  "test_api_bot": "cd /Users/admin/Documents/jfWorks/qiqi-bot && DEBUG=api tsx /Users/admin/Documents/jfWorks/x/packages/x-server/src/cli/cli.ts api",