@jayfong/x-server 2.48.0 → 2.49.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/lib/_cjs/cli/build_util.js +20 -12
- package/lib/_cjs/cli/cli.js +0 -0
- package/lib/_cjs/core/http_header.js +3 -5
- package/lib/_cjs/core/http_method.js +2 -3
- package/lib/_cjs/core/server.js +1 -2
- package/lib/_cjs/core/types.js +4 -12
- package/lib/_cjs/index.js +6 -0
- package/lib/_cjs/plugins/cookie.js +18 -0
- package/lib/_cjs/x.js +1 -2
- package/lib/cli/build_util.js +20 -12
- package/lib/core/define_bus.js +2 -0
- package/lib/core/server.js +1 -2
- package/lib/core/types.js +1 -5
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/plugins/cookie.d.ts +13 -0
- package/lib/plugins/cookie.js +12 -0
- package/package.json +2 -1
|
@@ -29,7 +29,9 @@ class BuildUtil {
|
|
|
29
29
|
await _fsExtra.default.ensureDir(tempDir);
|
|
30
30
|
|
|
31
31
|
// 处理 external
|
|
32
|
-
const external = (0, _vtils.uniq)(options.external || [])
|
|
32
|
+
const external = (0, _vtils.uniq)([...(options.external || []),
|
|
33
|
+
// bull 始终作为外部依赖
|
|
34
|
+
'bull']);
|
|
33
35
|
const externalWithVersions = (await Promise.all(external.map(async item => {
|
|
34
36
|
try {
|
|
35
37
|
// 为何不用 require.resolve:
|
|
@@ -91,17 +93,23 @@ class BuildUtil {
|
|
|
91
93
|
loader: 'js'
|
|
92
94
|
};
|
|
93
95
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
96
|
+
|
|
97
|
+
// build.onLoad(
|
|
98
|
+
// { filter: /\/bull\/lib\/commands\/index\.js$/ },
|
|
99
|
+
// async args => {
|
|
100
|
+
// let js = await fs.readFile(args.path, 'utf-8');
|
|
101
|
+
// js = js.replace(/__dirname/g, '"./assets/bull/commands"');
|
|
102
|
+
// await fs.copy(
|
|
103
|
+
// path.dirname(require.resolve('bull/lib/commands/index.js')),
|
|
104
|
+
// path.join(distDir, 'assets/bull/commands'),
|
|
105
|
+
// );
|
|
106
|
+
// return {
|
|
107
|
+
// contents: js,
|
|
108
|
+
// loader: 'js',
|
|
109
|
+
// };
|
|
110
|
+
// },
|
|
111
|
+
// );
|
|
112
|
+
|
|
105
113
|
build.onLoad({
|
|
106
114
|
filter: /\/vm2\/lib\/vm\.js$/
|
|
107
115
|
}, async args => {
|
package/lib/_cjs/cli/cli.js
CHANGED
|
File without changes
|
|
@@ -19,7 +19,7 @@ ${'/'}**
|
|
|
19
19
|
${item.pascalName} = '${item.name}',
|
|
20
20
|
`).join('\n\n')
|
|
21
21
|
*/
|
|
22
|
-
let HttpRequestHeader = /*#__PURE__*/function (HttpRequestHeader) {
|
|
22
|
+
let HttpRequestHeader = exports.HttpRequestHeader = /*#__PURE__*/function (HttpRequestHeader) {
|
|
23
23
|
HttpRequestHeader["A_IM"] = "A-IM";
|
|
24
24
|
HttpRequestHeader["ACCEPT"] = "Accept";
|
|
25
25
|
HttpRequestHeader["ACCEPT_CHARSET"] = "Accept-Charset";
|
|
@@ -78,8 +78,7 @@ let HttpRequestHeader = /*#__PURE__*/function (HttpRequestHeader) {
|
|
|
78
78
|
HttpRequestHeader["SAVE_DATA"] = "Save-Data";
|
|
79
79
|
return HttpRequestHeader;
|
|
80
80
|
}({});
|
|
81
|
-
exports.
|
|
82
|
-
let HttpResponseHeader = /*#__PURE__*/function (HttpResponseHeader) {
|
|
81
|
+
let HttpResponseHeader = exports.HttpResponseHeader = /*#__PURE__*/function (HttpResponseHeader) {
|
|
83
82
|
HttpResponseHeader["ACCESS_CONTROL_ALLOW_ORIGIN"] = "Access-Control-Allow-Origin";
|
|
84
83
|
HttpResponseHeader["ACCESS_CONTROL_ALLOW_CREDENTIALS"] = "Access-Control-Allow-Credentials";
|
|
85
84
|
HttpResponseHeader["ACCESS_CONTROL_EXPOSE_HEADERS"] = "Access-Control-Expose-Headers";
|
|
@@ -140,5 +139,4 @@ let HttpResponseHeader = /*#__PURE__*/function (HttpResponseHeader) {
|
|
|
140
139
|
HttpResponseHeader["X_UA_COMPATIBLE"] = "X-UA-Compatible";
|
|
141
140
|
HttpResponseHeader["X_XSS_PROTECTION"] = "X-XSS-Protection";
|
|
142
141
|
return HttpResponseHeader;
|
|
143
|
-
}({});
|
|
144
|
-
exports.HttpResponseHeader = HttpResponseHeader;
|
|
142
|
+
}({});
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.HandlerMethodToHttpMethod = void 0;
|
|
5
|
-
const HandlerMethodToHttpMethod = {
|
|
5
|
+
const HandlerMethodToHttpMethod = exports.HandlerMethodToHttpMethod = {
|
|
6
6
|
GET: 'GET',
|
|
7
7
|
POST: 'POST',
|
|
8
8
|
FILE: 'POST',
|
|
9
9
|
WS: 'GET',
|
|
10
10
|
XML: 'POST'
|
|
11
|
-
};
|
|
12
|
-
exports.HandlerMethodToHttpMethod = HandlerMethodToHttpMethod;
|
|
11
|
+
};
|
package/lib/_cjs/core/server.js
CHANGED
|
@@ -78,8 +78,7 @@ class Server {
|
|
|
78
78
|
const handlerOptions = item.handler.options;
|
|
79
79
|
const handlerMethod = handlerOptions.requestMethod || 'POST';
|
|
80
80
|
const isWS = handlerMethod === 'WS';
|
|
81
|
-
const url = `${appUrl}${
|
|
82
|
-
// 结构:/test/sss?x=2
|
|
81
|
+
const url = `${appUrl}${// 结构:/test/sss?x=2
|
|
83
82
|
path != null ? path : isWS ? res.url : req.url}`;
|
|
84
83
|
if (isWS) {
|
|
85
84
|
await item.handler.handle(undefined, {
|
package/lib/_cjs/core/types.js
CHANGED
|
@@ -2,15 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.XTask = exports.XServer = exports.XHandler = exports.XCron = void 0;
|
|
5
|
-
let XServer;
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
let
|
|
9
|
-
exports.XHandler = XHandler;
|
|
10
|
-
(function (_XHandler) {})(XHandler || (exports.XHandler = XHandler = {}));
|
|
11
|
-
let XTask;
|
|
12
|
-
exports.XTask = XTask;
|
|
13
|
-
(function (_XTask) {})(XTask || (exports.XTask = XTask = {}));
|
|
14
|
-
let XCron;
|
|
15
|
-
exports.XCron = XCron;
|
|
16
|
-
(function (_XCron) {})(XCron || (exports.XCron = XCron = {}));
|
|
5
|
+
let XServer = exports.XServer = void 0;
|
|
6
|
+
let XHandler = exports.XHandler = void 0;
|
|
7
|
+
let XTask = exports.XTask = void 0;
|
|
8
|
+
let XCron = exports.XCron = void 0;
|
package/lib/_cjs/index.js
CHANGED
|
@@ -91,6 +91,12 @@ Object.keys(_base).forEach(function (key) {
|
|
|
91
91
|
if (key in exports && exports[key] === _base[key]) return;
|
|
92
92
|
exports[key] = _base[key];
|
|
93
93
|
});
|
|
94
|
+
var _cookie = require("./plugins/cookie");
|
|
95
|
+
Object.keys(_cookie).forEach(function (key) {
|
|
96
|
+
if (key === "default" || key === "__esModule") return;
|
|
97
|
+
if (key in exports && exports[key] === _cookie[key]) return;
|
|
98
|
+
exports[key] = _cookie[key];
|
|
99
|
+
});
|
|
94
100
|
var _cors = require("./plugins/cors");
|
|
95
101
|
Object.keys(_cors).forEach(function (key) {
|
|
96
102
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.CookiePlugin = void 0;
|
|
6
|
+
var _cookie = _interopRequireDefault(require("@fastify/cookie"));
|
|
7
|
+
/**
|
|
8
|
+
* Cookie 支持插件
|
|
9
|
+
*/
|
|
10
|
+
class CookiePlugin {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
}
|
|
14
|
+
register(fastify) {
|
|
15
|
+
fastify.register(_cookie.default, this.options);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.CookiePlugin = CookiePlugin;
|
package/lib/_cjs/x.js
CHANGED
|
@@ -10,7 +10,7 @@ var _dispose = require("./services/dispose");
|
|
|
10
10
|
var _emoji = require("./services/emoji");
|
|
11
11
|
var _log = require("./services/log");
|
|
12
12
|
const env = JSON.parse(process.env.X_SERVER_ENVS || '{}');
|
|
13
|
-
const x = {
|
|
13
|
+
const x = exports.x = {
|
|
14
14
|
appId: env.APP_ID,
|
|
15
15
|
env: env,
|
|
16
16
|
dataDir: _path.default.join(_os.default.homedir(), `.xs/${env.APP_ID}`),
|
|
@@ -21,7 +21,6 @@ const x = {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
-
exports.x = x;
|
|
25
24
|
_fsExtra.default.ensureDirSync(x.dataDir);
|
|
26
25
|
x.register(new _dispose.DisposeService({
|
|
27
26
|
disposeOnExit: true
|
package/lib/cli/build_util.js
CHANGED
|
@@ -23,7 +23,9 @@ export class BuildUtil {
|
|
|
23
23
|
await fs.ensureDir(tempDir);
|
|
24
24
|
|
|
25
25
|
// 处理 external
|
|
26
|
-
const external = uniq(options.external || [])
|
|
26
|
+
const external = uniq([...(options.external || []),
|
|
27
|
+
// bull 始终作为外部依赖
|
|
28
|
+
'bull']);
|
|
27
29
|
const externalWithVersions = (await Promise.all(external.map(async item => {
|
|
28
30
|
try {
|
|
29
31
|
// 为何不用 require.resolve:
|
|
@@ -85,17 +87,23 @@ export class BuildUtil {
|
|
|
85
87
|
loader: 'js'
|
|
86
88
|
};
|
|
87
89
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
|
|
91
|
+
// build.onLoad(
|
|
92
|
+
// { filter: /\/bull\/lib\/commands\/index\.js$/ },
|
|
93
|
+
// async args => {
|
|
94
|
+
// let js = await fs.readFile(args.path, 'utf-8');
|
|
95
|
+
// js = js.replace(/__dirname/g, '"./assets/bull/commands"');
|
|
96
|
+
// await fs.copy(
|
|
97
|
+
// path.dirname(require.resolve('bull/lib/commands/index.js')),
|
|
98
|
+
// path.join(distDir, 'assets/bull/commands'),
|
|
99
|
+
// );
|
|
100
|
+
// return {
|
|
101
|
+
// contents: js,
|
|
102
|
+
// loader: 'js',
|
|
103
|
+
// };
|
|
104
|
+
// },
|
|
105
|
+
// );
|
|
106
|
+
|
|
99
107
|
build.onLoad({
|
|
100
108
|
filter: /\/vm2\/lib\/vm\.js$/
|
|
101
109
|
}, async args => {
|
package/lib/core/define_bus.js
CHANGED
|
@@ -21,5 +21,7 @@ export function defineBus() {
|
|
|
21
21
|
// Unfortunately, this has the result of giving a poor error message when
|
|
22
22
|
// you mix up types.
|
|
23
23
|
// 0: https://github.com/Microsoft/TypeScript/issues/26013)
|
|
24
|
+
|
|
24
25
|
// TODO: Stash under a symbol key once TS compiler bug is fixed
|
|
26
|
+
|
|
25
27
|
// EventEmitter method overrides
|
package/lib/core/server.js
CHANGED
|
@@ -72,8 +72,7 @@ export class Server {
|
|
|
72
72
|
const handlerOptions = item.handler.options;
|
|
73
73
|
const handlerMethod = handlerOptions.requestMethod || 'POST';
|
|
74
74
|
const isWS = handlerMethod === 'WS';
|
|
75
|
-
const url = `${appUrl}${
|
|
76
|
-
// 结构:/test/sss?x=2
|
|
75
|
+
const url = `${appUrl}${// 结构:/test/sss?x=2
|
|
77
76
|
path != null ? path : isWS ? res.url : req.url}`;
|
|
78
77
|
if (isWS) {
|
|
79
78
|
await item.handler.handle(undefined, {
|
package/lib/core/types.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
export let XServer;
|
|
2
|
-
(function (_XServer) {})(XServer || (XServer = {}));
|
|
3
2
|
export let XHandler;
|
|
4
|
-
(function (_XHandler) {})(XHandler || (XHandler = {}));
|
|
5
3
|
export let XTask;
|
|
6
|
-
|
|
7
|
-
export let XCron;
|
|
8
|
-
(function (_XCron) {})(XCron || (XCron = {}));
|
|
4
|
+
export let XCron;
|
package/lib/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from './core/http_redirect';
|
|
|
13
13
|
export * from './core/server';
|
|
14
14
|
export * from './core/types';
|
|
15
15
|
export * from './plugins/base';
|
|
16
|
+
export * from './plugins/cookie';
|
|
16
17
|
export * from './plugins/cors';
|
|
17
18
|
export * from './plugins/file_parser';
|
|
18
19
|
export * from './plugins/form_body_parser';
|
package/lib/index.js
CHANGED
|
@@ -14,6 +14,7 @@ export * from "./core/http_redirect";
|
|
|
14
14
|
export * from "./core/server";
|
|
15
15
|
export * from "./core/types";
|
|
16
16
|
export * from "./plugins/base";
|
|
17
|
+
export * from "./plugins/cookie";
|
|
17
18
|
export * from "./plugins/cors";
|
|
18
19
|
export * from "./plugins/file_parser";
|
|
19
20
|
export * from "./plugins/form_body_parser";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FastifyCookieOptions } from '@fastify/cookie';
|
|
2
|
+
import { FastifyInstance } from 'fastify';
|
|
3
|
+
import { BasePlugin } from './base';
|
|
4
|
+
export interface CookiePluginOptions extends FastifyCookieOptions {
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Cookie 支持插件
|
|
8
|
+
*/
|
|
9
|
+
export declare class CookiePlugin implements BasePlugin {
|
|
10
|
+
private options?;
|
|
11
|
+
constructor(options?: CookiePluginOptions);
|
|
12
|
+
register(fastify: FastifyInstance<any, any, any, any, any>): void;
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayfong/x-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.49.2",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "lib/_cjs/index.js",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"test_api_qiqi": "cd /Users/admin/Documents/jfWorks/qiqi-server && DEBUG=api tsx /Users/admin/Documents/jfWorks/x/packages/x-server/src/cli/cli.ts api"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@fastify/cookie": "^9.4.0",
|
|
25
26
|
"@fastify/cors": "^8.3.0",
|
|
26
27
|
"@fastify/formbody": "^7.4.0",
|
|
27
28
|
"@fastify/multipart": "^7.7.0",
|