@innet/server 2.0.0-alpha.24 → 2.0.0-alpha.25
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/handler/handler.d.ts +5 -5
- package/handler/handler.es6.js +3 -3
- package/handler/handler.js +3 -3
- package/hooks/index.d.ts +1 -0
- package/hooks/index.es6.js +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useClientIp/useClientIp.d.ts +1 -1
- package/hooks/useEndpoint/useEndpoint.d.ts +1 -1
- package/hooks/useSchemaType/useSchemaType.d.ts +3 -3
- package/hooks/useSchemaType/useSchemaType.es6.js +5 -5
- package/hooks/useSchemaType/useSchemaType.js +5 -5
- package/hooks/useServer/useServer.d.ts +1 -1
- package/hooks/useServerPort/index.d.ts +1 -0
- package/hooks/useServerPort/index.es6.js +1 -0
- package/hooks/useServerPort/index.js +10 -0
- package/hooks/useServerPort/useServerPort.d.ts +3 -0
- package/hooks/useServerPort/useServerPort.es6.js +14 -0
- package/hooks/useServerPort/useServerPort.js +19 -0
- package/index.es6.js +1 -0
- package/index.js +3 -0
- package/package.json +1 -1
- package/plugins/main/api/api.d.ts +10 -10
- package/plugins/main/api/api.es6.js +7 -7
- package/plugins/main/api/api.js +7 -7
- package/plugins/main/contact/contact.d.ts +2 -2
- package/plugins/main/endpoint/endpoint.d.ts +15 -15
- package/plugins/main/endpoint/endpoint.es6.js +3 -3
- package/plugins/main/endpoint/endpoint.js +3 -3
- package/plugins/main/host/host.d.ts +5 -5
- package/plugins/main/license/license.d.ts +5 -5
- package/plugins/main/param/param.d.ts +11 -11
- package/plugins/main/param/param.es6.js +3 -3
- package/plugins/main/param/param.js +3 -3
- package/plugins/main/response/response.d.ts +1 -1
- package/plugins/main/response/response.es6.js +2 -2
- package/plugins/main/response/response.js +2 -2
- package/plugins/main/server/server.d.ts +4 -4
- package/plugins/main/server/server.es6.js +9 -7
- package/plugins/main/server/server.js +9 -7
- package/plugins/main/tag/tag.d.ts +2 -2
- package/plugins/main/tag/tag.es6.js +1 -1
- package/plugins/main/tag/tag.js +1 -1
- package/plugins/main/variable/variable.d.ts +5 -5
- package/plugins/main/variable/variable.es6.js +3 -1
- package/plugins/main/variable/variable.js +3 -1
- package/plugins/request/cms/cms.es6.js +2 -2
- package/plugins/request/cms/cms.js +2 -2
- package/plugins/request/error/error.d.ts +40 -40
- package/plugins/request/error/error.es6.js +42 -42
- package/plugins/request/error/error.js +42 -42
- package/plugins/request/header/header.es6.js +1 -1
- package/plugins/request/header/header.js +1 -1
- package/plugins/request/proxy/proxy.d.ts +2 -2
- package/plugins/request/proxy/proxy.es6.js +2 -2
- package/plugins/request/proxy/proxy.js +2 -2
- package/plugins/request/redirect/redirect.d.ts +7 -7
- package/plugins/request/redirect/redirect.es6.js +7 -7
- package/plugins/request/redirect/redirect.js +7 -7
- package/plugins/request/success/success.d.ts +6 -6
- package/plugins/request/success/success.es6.js +8 -8
- package/plugins/request/success/success.js +8 -8
- package/plugins/schema/binary/binary.d.ts +3 -3
- package/plugins/schema/date/date.d.ts +1 -1
- package/plugins/schema/date/date.es6.js +3 -3
- package/plugins/schema/date/date.js +3 -3
- package/plugins/schema/field/field.es6.js +1 -1
- package/plugins/schema/field/field.js +1 -1
- package/plugins/schema/integer/integer.d.ts +3 -3
- package/plugins/schema/integer/integer.es6.js +1 -1
- package/plugins/schema/integer/integer.js +1 -1
- package/plugins/schema/number/number.d.ts +2 -2
- package/plugins/schema/number/number.es6.js +1 -1
- package/plugins/schema/number/number.js +1 -1
- package/plugins/schema/string/string.d.ts +2 -2
- package/plugins/schema/string/string.es6.js +1 -1
- package/plugins/schema/string/string.js +1 -1
- package/plugins/utils/dts/dts.d.ts +1 -1
- package/plugins/utils/dts/dts.es6.js +1 -1
- package/plugins/utils/dts/dts.js +1 -1
- package/plugins/utils/env/env.d.ts +1 -1
- package/plugins/utils/env/env.es6.js +1 -1
- package/plugins/utils/env/env.js +1 -1
- package/plugins/utils/protection/protection.d.ts +3 -3
- package/plugins/utils/protection/protection.es6.js +3 -3
- package/plugins/utils/protection/protection.js +3 -3
- package/plugins/utils/swagger/swagger.es6.js +1 -1
- package/plugins/utils/swagger/swagger.js +1 -1
- package/types.d.ts +13 -13
- package/utils/FileData/Bin.d.ts +13 -13
- package/utils/FileData/Bin.es6.js +2 -2
- package/utils/FileData/Bin.js +2 -2
- package/utils/action/Action.d.ts +12 -12
- package/utils/action/Action.es6.js +80 -80
- package/utils/action/Action.js +79 -79
- package/utils/dateFormat/dateFormat.d.ts +1 -1
- package/utils/dateFormat/dateFormat.es6.js +1 -1
- package/utils/dateFormat/dateFormat.js +1 -1
- package/utils/generateTypes/generateTypes.es6.js +3 -3
- package/utils/generateTypes/generateTypes.js +3 -3
- package/utils/getOrAdd/getOrAdd.d.ts +1 -1
- package/utils/httpOnStart/httpOnStart.d.ts +1 -1
- package/utils/httpOnStart/httpOnStart.es6.js +1 -1
- package/utils/httpOnStart/httpOnStart.js +1 -1
- package/utils/rules/binaryAccept/binaryAccept.es6.js +2 -2
- package/utils/rules/binaryAccept/binaryAccept.js +2 -2
- package/utils/rules/dateTo/dateTo.d.ts +1 -1
- package/utils/rules/helpers.d.ts +1 -1
- package/utils/rules/int/int.es6.js +2 -2
- package/utils/rules/int/int.js +2 -2
- package/utils/rules/max/max.d.ts +1 -1
- package/utils/rules/max/max.es6.js +3 -3
- package/utils/rules/max/max.js +3 -3
- package/utils/rules/maxBin/maxBin.es6.js +2 -2
- package/utils/rules/maxBin/maxBin.js +2 -2
- package/utils/rules/maxDate/maxDate.es6.js +1 -1
- package/utils/rules/maxDate/maxDate.js +1 -1
- package/utils/rules/maxLength/maxLength.es6.js +2 -2
- package/utils/rules/maxLength/maxLength.js +2 -2
- package/utils/rules/min/min.d.ts +1 -1
- package/utils/rules/min/min.es6.js +3 -3
- package/utils/rules/min/min.js +3 -3
- package/utils/rules/minBin/minBin.es6.js +2 -2
- package/utils/rules/minBin/minBin.js +2 -2
- package/utils/rules/minDate/minDate.es6.js +1 -1
- package/utils/rules/minDate/minDate.js +1 -1
- package/utils/rules/minLength/minLength.es6.js +2 -2
- package/utils/rules/minLength/minLength.js +2 -2
- package/utils/rules/pattern/pattern.d.ts +1 -1
- package/utils/rules/pattern/pattern.es6.js +2 -1
- package/utils/rules/pattern/pattern.js +2 -1
|
@@ -13,7 +13,7 @@ export interface ResponseProps {
|
|
|
13
13
|
* For example, 2XX represents all response codes between [200-299].
|
|
14
14
|
* Only the following range definitions are allowed: 1XX, 2XX, 3XX, 4XX, and 5XX.
|
|
15
15
|
* */
|
|
16
|
-
status?:
|
|
16
|
+
status?: 'default' | `${1 | 2 | 3 | 4 | 5}XX` | StatusKey | number;
|
|
17
17
|
type?: string;
|
|
18
18
|
}
|
|
19
19
|
export declare const statuses: Record<StatusKey, number>;
|
|
@@ -16,7 +16,7 @@ const statuses = Object.assign(Object.assign(Object.assign({}, errorStatuses), r
|
|
|
16
16
|
const response = () => {
|
|
17
17
|
var _a;
|
|
18
18
|
let { description = '', status = 'default', type = 'application/json', } = useProps() || {};
|
|
19
|
-
const { operation, props: { path } } = useEndpoint();
|
|
19
|
+
const { operation, props: { path }, } = useEndpoint();
|
|
20
20
|
const children = useChildren();
|
|
21
21
|
const handler = useNewHandler();
|
|
22
22
|
const endpoint = useContext(endpointContext);
|
|
@@ -35,10 +35,10 @@ const response = () => {
|
|
|
35
35
|
}
|
|
36
36
|
const schema = {};
|
|
37
37
|
const response = {
|
|
38
|
-
description,
|
|
39
38
|
content: Object.assign(Object.assign({}, defaultResponse === null || defaultResponse === void 0 ? void 0 : defaultResponse.content), { [type]: {
|
|
40
39
|
schema,
|
|
41
40
|
} }),
|
|
41
|
+
description,
|
|
42
42
|
};
|
|
43
43
|
operation.responses[status] = response;
|
|
44
44
|
schemaContext.set(handler, schema);
|
|
@@ -24,7 +24,7 @@ const statuses = Object.assign(Object.assign(Object.assign({}, error.errorStatus
|
|
|
24
24
|
const response = () => {
|
|
25
25
|
var _a;
|
|
26
26
|
let { description = '', status = 'default', type = 'application/json', } = jsx.useProps() || {};
|
|
27
|
-
const { operation, props: { path } } = useEndpoint.useEndpoint();
|
|
27
|
+
const { operation, props: { path }, } = useEndpoint.useEndpoint();
|
|
28
28
|
const children = jsx.useChildren();
|
|
29
29
|
const handler = innet.useNewHandler();
|
|
30
30
|
const endpoint = jsx.useContext(useEndpoint.endpointContext);
|
|
@@ -43,10 +43,10 @@ const response = () => {
|
|
|
43
43
|
}
|
|
44
44
|
const schema = {};
|
|
45
45
|
const response = {
|
|
46
|
-
description,
|
|
47
46
|
content: Object.assign(Object.assign({}, defaultResponse === null || defaultResponse === void 0 ? void 0 : defaultResponse.content), { [type]: {
|
|
48
47
|
schema,
|
|
49
48
|
} }),
|
|
49
|
+
description,
|
|
50
50
|
};
|
|
51
51
|
operation.responses[status] = response;
|
|
52
52
|
useSchemaContext.schemaContext.set(handler, schema);
|
|
@@ -3,11 +3,11 @@ import { type HandlerPlugin } from 'innet';
|
|
|
3
3
|
import { type IncomingMessage, type ServerResponse } from 'http';
|
|
4
4
|
import { type ServerStartParams, type SSL } from '../../../types';
|
|
5
5
|
export interface ServerProps {
|
|
6
|
+
onClose?: () => any;
|
|
7
|
+
onError?: (e: Error) => any;
|
|
8
|
+
onRequest?: (req: IncomingMessage, res: ServerResponse) => any;
|
|
9
|
+
onStart?: (params: ServerStartParams) => any;
|
|
6
10
|
port?: number;
|
|
7
11
|
ssl?: SSL;
|
|
8
|
-
onStart?: (params: ServerStartParams) => any;
|
|
9
|
-
onRequest?: (req: IncomingMessage, res: ServerResponse) => any;
|
|
10
|
-
onError?: (e: Error) => any;
|
|
11
|
-
onClose?: () => any;
|
|
12
12
|
}
|
|
13
13
|
export declare const server: HandlerPlugin;
|
|
@@ -8,6 +8,7 @@ import '../../../hooks/index.es6.js';
|
|
|
8
8
|
import '../../../utils/index.es6.js';
|
|
9
9
|
import { serverContext } from '../../../hooks/useServer/useServer.es6.js';
|
|
10
10
|
import { serverPlugins } from '../../../hooks/useServerPlugins/useServerPlugins.es6.js';
|
|
11
|
+
import { serverPortContext } from '../../../hooks/useServerPort/useServerPort.es6.js';
|
|
11
12
|
import { Action } from '../../../utils/action/Action.es6.js';
|
|
12
13
|
import { actionContext } from '../../../hooks/useAction/useAction.es6.js';
|
|
13
14
|
|
|
@@ -16,9 +17,9 @@ const isInvalidPath = require('is-invalid-path');
|
|
|
16
17
|
const server = () => {
|
|
17
18
|
var _a, _b, _c;
|
|
18
19
|
const handler = useNewHandler();
|
|
19
|
-
const { props = {},
|
|
20
|
+
const { children, props = {}, } = useApp();
|
|
20
21
|
const { env } = process;
|
|
21
|
-
let { ssl: {
|
|
22
|
+
let { ssl: { cert = (_a = env.INNET_SSL_CRT) !== null && _a !== void 0 ? _a : 'localhost.crt', key = (_b = env.INNET_SSL_KEY) !== null && _b !== void 0 ? _b : 'localhost.key', } = {}, } = props;
|
|
22
23
|
try {
|
|
23
24
|
if (!isInvalidPath(key)) {
|
|
24
25
|
key = fs.readFileSync(key).toString();
|
|
@@ -32,11 +33,12 @@ const server = () => {
|
|
|
32
33
|
cert = '';
|
|
33
34
|
}
|
|
34
35
|
const https = Boolean(key && cert);
|
|
35
|
-
const { port = Number((_c = env.INNET_PORT) !== null && _c !== void 0 ? _c : (https ? 442 : 80)),
|
|
36
|
+
const { onClose, onError, onRequest, onStart, port = Number((_c = env.INNET_PORT) !== null && _c !== void 0 ? _c : (https ? 442 : 80)), } = props;
|
|
36
37
|
const plugins = new Set();
|
|
37
|
-
const server = https ? http2.createServer({
|
|
38
|
-
serverContext.set(handler, {
|
|
38
|
+
const server = https ? http2.createServer({ cert, key }) : http.createServer();
|
|
39
|
+
serverContext.set(handler, { port, server });
|
|
39
40
|
serverPlugins.set(handler, plugins);
|
|
41
|
+
serverPortContext.set(handler, port);
|
|
40
42
|
onDestroy(() => {
|
|
41
43
|
server.close();
|
|
42
44
|
});
|
|
@@ -61,11 +63,11 @@ const server = () => {
|
|
|
61
63
|
}
|
|
62
64
|
});
|
|
63
65
|
}
|
|
64
|
-
innet({ type: server
|
|
66
|
+
innet({ props, type: server }, requestHandler);
|
|
65
67
|
});
|
|
66
68
|
innet(children, handler);
|
|
67
69
|
server.listen(port, () => {
|
|
68
|
-
onStart === null || onStart === void 0 ? void 0 : onStart({
|
|
70
|
+
onStart === null || onStart === void 0 ? void 0 : onStart({ https, port });
|
|
69
71
|
});
|
|
70
72
|
};
|
|
71
73
|
|
|
@@ -12,6 +12,7 @@ require('../../../hooks/index.js');
|
|
|
12
12
|
require('../../../utils/index.js');
|
|
13
13
|
var useServer = require('../../../hooks/useServer/useServer.js');
|
|
14
14
|
var useServerPlugins = require('../../../hooks/useServerPlugins/useServerPlugins.js');
|
|
15
|
+
var useServerPort = require('../../../hooks/useServerPort/useServerPort.js');
|
|
15
16
|
var Action = require('../../../utils/action/Action.js');
|
|
16
17
|
var useAction = require('../../../hooks/useAction/useAction.js');
|
|
17
18
|
|
|
@@ -27,9 +28,9 @@ const isInvalidPath = require('is-invalid-path');
|
|
|
27
28
|
const server = () => {
|
|
28
29
|
var _a, _b, _c;
|
|
29
30
|
const handler = innet.useNewHandler();
|
|
30
|
-
const { props = {},
|
|
31
|
+
const { children, props = {}, } = innet.useApp();
|
|
31
32
|
const { env } = process;
|
|
32
|
-
let { ssl: {
|
|
33
|
+
let { ssl: { cert = (_a = env.INNET_SSL_CRT) !== null && _a !== void 0 ? _a : 'localhost.crt', key = (_b = env.INNET_SSL_KEY) !== null && _b !== void 0 ? _b : 'localhost.key', } = {}, } = props;
|
|
33
34
|
try {
|
|
34
35
|
if (!isInvalidPath(key)) {
|
|
35
36
|
key = fs__default["default"].readFileSync(key).toString();
|
|
@@ -43,11 +44,12 @@ const server = () => {
|
|
|
43
44
|
cert = '';
|
|
44
45
|
}
|
|
45
46
|
const https = Boolean(key && cert);
|
|
46
|
-
const { port = Number((_c = env.INNET_PORT) !== null && _c !== void 0 ? _c : (https ? 442 : 80)),
|
|
47
|
+
const { onClose, onError, onRequest, onStart, port = Number((_c = env.INNET_PORT) !== null && _c !== void 0 ? _c : (https ? 442 : 80)), } = props;
|
|
47
48
|
const plugins = new Set();
|
|
48
|
-
const server = https ? http2__default["default"].createServer({
|
|
49
|
-
useServer.serverContext.set(handler, {
|
|
49
|
+
const server = https ? http2__default["default"].createServer({ cert, key }) : http__default["default"].createServer();
|
|
50
|
+
useServer.serverContext.set(handler, { port, server });
|
|
50
51
|
useServerPlugins.serverPlugins.set(handler, plugins);
|
|
52
|
+
useServerPort.serverPortContext.set(handler, port);
|
|
51
53
|
watchState.onDestroy(() => {
|
|
52
54
|
server.close();
|
|
53
55
|
});
|
|
@@ -72,11 +74,11 @@ const server = () => {
|
|
|
72
74
|
}
|
|
73
75
|
});
|
|
74
76
|
}
|
|
75
|
-
innet__default["default"]({ type: server
|
|
77
|
+
innet__default["default"]({ props, type: server }, requestHandler);
|
|
76
78
|
});
|
|
77
79
|
innet__default["default"](children, handler);
|
|
78
80
|
server.listen(port, () => {
|
|
79
|
-
onStart === null || onStart === void 0 ? void 0 : onStart({
|
|
81
|
+
onStart === null || onStart === void 0 ? void 0 : onStart({ https, port });
|
|
80
82
|
});
|
|
81
83
|
};
|
|
82
84
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
export interface TagProps {
|
|
3
|
-
/** The name of the tag. */
|
|
4
|
-
name: string;
|
|
5
3
|
/**
|
|
6
4
|
* A description for the tag.
|
|
7
5
|
* [CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text representation.
|
|
8
6
|
* */
|
|
9
7
|
description?: string;
|
|
8
|
+
/** The name of the tag. */
|
|
9
|
+
name: string;
|
|
10
10
|
}
|
|
11
11
|
export declare const tag: HandlerPlugin;
|
|
@@ -8,7 +8,7 @@ const tag = () => {
|
|
|
8
8
|
if (useContext(tagContext)) {
|
|
9
9
|
throw Error('You cannot use a <tag> inside another one');
|
|
10
10
|
}
|
|
11
|
-
const { name,
|
|
11
|
+
const { description, name, } = useProps();
|
|
12
12
|
const children = useChildren();
|
|
13
13
|
const { docs } = useApi();
|
|
14
14
|
const tag = { name };
|
package/plugins/main/tag/tag.js
CHANGED
|
@@ -16,7 +16,7 @@ const tag = () => {
|
|
|
16
16
|
if (jsx.useContext(useTag.tagContext)) {
|
|
17
17
|
throw Error('You cannot use a <tag> inside another one');
|
|
18
18
|
}
|
|
19
|
-
const { name,
|
|
19
|
+
const { description, name, } = jsx.useProps();
|
|
20
20
|
const children = jsx.useChildren();
|
|
21
21
|
const { docs } = useApi.useApi();
|
|
22
22
|
const tag = { name };
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
export interface VariableProps {
|
|
3
|
+
/**
|
|
4
|
+
* An optional description for the server variable.
|
|
5
|
+
* [CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text representation.
|
|
6
|
+
* */
|
|
7
|
+
description?: string;
|
|
3
8
|
/**
|
|
4
9
|
* A server url parameter
|
|
5
10
|
* */
|
|
@@ -15,10 +20,5 @@ export interface VariableProps {
|
|
|
15
20
|
* The array MUST NOT be empty.
|
|
16
21
|
* */
|
|
17
22
|
values?: [string, string, ...string[]];
|
|
18
|
-
/**
|
|
19
|
-
* An optional description for the server variable.
|
|
20
|
-
* [CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text representation.
|
|
21
|
-
* */
|
|
22
|
-
description?: string;
|
|
23
23
|
}
|
|
24
24
|
export declare const variable: HandlerPlugin;
|
|
@@ -5,7 +5,9 @@ import { useHost } from '../../../hooks/useHost/useHost.es6.js';
|
|
|
5
5
|
|
|
6
6
|
const variable = () => {
|
|
7
7
|
const { server } = useHost();
|
|
8
|
-
const _a = useProps(), { key, values,
|
|
8
|
+
const _a = useProps(), { key, values,
|
|
9
|
+
// predefine
|
|
10
|
+
value = values === null || values === void 0 ? void 0 : values[0] } = _a, rest = __rest(_a, ["key", "values", "value"]);
|
|
9
11
|
if (!server.variables) {
|
|
10
12
|
server.variables = {};
|
|
11
13
|
}
|
|
@@ -9,7 +9,9 @@ var useHost = require('../../../hooks/useHost/useHost.js');
|
|
|
9
9
|
|
|
10
10
|
const variable = () => {
|
|
11
11
|
const { server } = useHost.useHost();
|
|
12
|
-
const _a = jsx.useProps(), { key, values,
|
|
12
|
+
const _a = jsx.useProps(), { key, values,
|
|
13
|
+
// predefine
|
|
14
|
+
value = values === null || values === void 0 ? void 0 : values[0] } = _a, rest = tslib.__rest(_a, ["key", "values", "value"]);
|
|
13
15
|
if (!server.variables) {
|
|
14
16
|
server.variables = {};
|
|
15
17
|
}
|
|
@@ -7,7 +7,7 @@ import { usePath } from '../../../hooks/usePath/usePath.es6.js';
|
|
|
7
7
|
import { file } from '../file/file.es6.js';
|
|
8
8
|
|
|
9
9
|
function cms() {
|
|
10
|
-
const {
|
|
10
|
+
const { dir = process.env.INNET_CMS_DIR || '.', prefix = process.env.INNET_CMS_PREFIX || '/', } = useProps() || {};
|
|
11
11
|
const children = useChildren();
|
|
12
12
|
const handler = useHandler();
|
|
13
13
|
let url = usePath();
|
|
@@ -18,7 +18,7 @@ function cms() {
|
|
|
18
18
|
return innet(children, handler);
|
|
19
19
|
}
|
|
20
20
|
const filePath = path.join(dir, url);
|
|
21
|
-
innet({
|
|
21
|
+
innet({ children, props: { path: filePath }, type: file }, handler);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export { cms };
|
|
@@ -16,7 +16,7 @@ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
|
16
16
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
17
17
|
|
|
18
18
|
function cms() {
|
|
19
|
-
const {
|
|
19
|
+
const { dir = process.env.INNET_CMS_DIR || '.', prefix = process.env.INNET_CMS_PREFIX || '/', } = jsx.useProps() || {};
|
|
20
20
|
const children = jsx.useChildren();
|
|
21
21
|
const handler = innet.useHandler();
|
|
22
22
|
let url = usePath.usePath();
|
|
@@ -27,7 +27,7 @@ function cms() {
|
|
|
27
27
|
return innet__default["default"](children, handler);
|
|
28
28
|
}
|
|
29
29
|
const filePath = path__default["default"].join(dir, url);
|
|
30
|
-
innet__default["default"]({
|
|
30
|
+
innet__default["default"]({ children, props: { path: filePath }, type: file.file }, handler);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
exports.cms = cms;
|
|
@@ -1,56 +1,56 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
export declare const errorStatuses: {
|
|
3
|
+
readonly aTimeoutOccurred: 524;
|
|
4
|
+
readonly authenticationTimeout: 419;
|
|
5
|
+
readonly badGateway: 502;
|
|
3
6
|
readonly badRequest: 400;
|
|
4
|
-
readonly
|
|
5
|
-
readonly
|
|
6
|
-
readonly forbidden: 403;
|
|
7
|
-
readonly notFound: 404;
|
|
8
|
-
readonly methodNotAllowed: 405;
|
|
9
|
-
readonly notAcceptable: 406;
|
|
10
|
-
readonly proxyAuthenticationRequired: 407;
|
|
11
|
-
readonly requestTimeout: 408;
|
|
7
|
+
readonly bandwidthLimitExceeded: 509;
|
|
8
|
+
readonly clientClosedRequest: 499;
|
|
12
9
|
readonly conflict: 409;
|
|
13
|
-
readonly
|
|
14
|
-
readonly lengthRequired: 411;
|
|
15
|
-
readonly preconditionFailed: 412;
|
|
16
|
-
readonly payloadTooLarge: 413;
|
|
17
|
-
readonly URITooLong: 414;
|
|
18
|
-
readonly unsupportedMediaType: 415;
|
|
19
|
-
readonly rangeNotSatisfiable: 416;
|
|
10
|
+
readonly connectionTimedOut: 522;
|
|
20
11
|
readonly expectationFailed: 417;
|
|
21
|
-
readonly imATeapot: 418;
|
|
22
|
-
readonly authenticationTimeout: 419;
|
|
23
|
-
readonly misdirectedRequest: 421;
|
|
24
|
-
readonly unprocessableEntity: 422;
|
|
25
|
-
readonly locked: 423;
|
|
26
12
|
readonly failedDependency: 424;
|
|
27
|
-
readonly
|
|
28
|
-
readonly upgradeRequired: 426;
|
|
29
|
-
readonly preconditionRequired: 428;
|
|
30
|
-
readonly tooManyRequests: 429;
|
|
31
|
-
readonly requestHeaderFieldsTooLarge: 431;
|
|
32
|
-
readonly retryWith: 449;
|
|
33
|
-
readonly unavailableForLegalReasons: 451;
|
|
34
|
-
readonly clientClosedRequest: 499;
|
|
35
|
-
readonly internalServerError: 500;
|
|
36
|
-
readonly notImplemented: 501;
|
|
37
|
-
readonly badGateway: 502;
|
|
38
|
-
readonly serviceUnavailable: 503;
|
|
13
|
+
readonly forbidden: 403;
|
|
39
14
|
readonly gatewayTimeout: 504;
|
|
15
|
+
readonly gone: 410;
|
|
40
16
|
readonly HTTPVersionNotSupported: 505;
|
|
41
|
-
readonly
|
|
17
|
+
readonly imATeapot: 418;
|
|
42
18
|
readonly insufficientStorage: 507;
|
|
19
|
+
readonly internalServerError: 500;
|
|
20
|
+
readonly invalidSSLCertificate: 526;
|
|
21
|
+
readonly lengthRequired: 411;
|
|
22
|
+
readonly locked: 423;
|
|
43
23
|
readonly loopDetected: 508;
|
|
44
|
-
readonly
|
|
45
|
-
readonly
|
|
24
|
+
readonly methodNotAllowed: 405;
|
|
25
|
+
readonly misdirectedRequest: 421;
|
|
46
26
|
readonly networkAuthenticationRequired: 511;
|
|
47
|
-
readonly
|
|
48
|
-
readonly
|
|
49
|
-
readonly
|
|
27
|
+
readonly notAcceptable: 406;
|
|
28
|
+
readonly notExtended: 510;
|
|
29
|
+
readonly notFound: 404;
|
|
30
|
+
readonly notImplemented: 501;
|
|
50
31
|
readonly originIsUnreachable: 523;
|
|
51
|
-
readonly
|
|
32
|
+
readonly payloadTooLarge: 413;
|
|
33
|
+
readonly paymentRequired: 402;
|
|
34
|
+
readonly preconditionFailed: 412;
|
|
35
|
+
readonly preconditionRequired: 428;
|
|
36
|
+
readonly proxyAuthenticationRequired: 407;
|
|
37
|
+
readonly rangeNotSatisfiable: 416;
|
|
38
|
+
readonly requestHeaderFieldsTooLarge: 431;
|
|
39
|
+
readonly requestTimeout: 408;
|
|
40
|
+
readonly retryWith: 449;
|
|
41
|
+
readonly serviceUnavailable: 503;
|
|
52
42
|
readonly SSLHandshakeFailed: 525;
|
|
53
|
-
readonly
|
|
43
|
+
readonly tooEarly: 425;
|
|
44
|
+
readonly tooManyRequests: 429;
|
|
45
|
+
readonly unauthorized: 401;
|
|
46
|
+
readonly unavailableForLegalReasons: 451;
|
|
47
|
+
readonly unknownError: 520;
|
|
48
|
+
readonly unprocessableEntity: 422;
|
|
49
|
+
readonly unsupportedMediaType: 415;
|
|
50
|
+
readonly upgradeRequired: 426;
|
|
51
|
+
readonly URITooLong: 414;
|
|
52
|
+
readonly variantAlsoNegotiates: 506;
|
|
53
|
+
readonly webServerIsDown: 521;
|
|
54
54
|
};
|
|
55
55
|
export type ErrorStatuses = keyof typeof errorStatuses;
|
|
56
56
|
export interface ErrorProps {
|
|
@@ -5,57 +5,57 @@ import { useResponse } from '../../../hooks/useResponse/useResponse.es6.js';
|
|
|
5
5
|
import { JSONString } from '../../../utils/JSONString/JSONString.es6.js';
|
|
6
6
|
|
|
7
7
|
const errorStatuses = {
|
|
8
|
+
aTimeoutOccurred: 524,
|
|
9
|
+
authenticationTimeout: 419,
|
|
10
|
+
badGateway: 502,
|
|
8
11
|
badRequest: 400,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
forbidden: 403,
|
|
12
|
-
notFound: 404,
|
|
13
|
-
methodNotAllowed: 405,
|
|
14
|
-
notAcceptable: 406,
|
|
15
|
-
proxyAuthenticationRequired: 407,
|
|
16
|
-
requestTimeout: 408,
|
|
12
|
+
bandwidthLimitExceeded: 509,
|
|
13
|
+
clientClosedRequest: 499,
|
|
17
14
|
conflict: 409,
|
|
18
|
-
|
|
19
|
-
lengthRequired: 411,
|
|
20
|
-
preconditionFailed: 412,
|
|
21
|
-
payloadTooLarge: 413,
|
|
22
|
-
URITooLong: 414,
|
|
23
|
-
unsupportedMediaType: 415,
|
|
24
|
-
rangeNotSatisfiable: 416,
|
|
15
|
+
connectionTimedOut: 522,
|
|
25
16
|
expectationFailed: 417,
|
|
26
|
-
imATeapot: 418,
|
|
27
|
-
authenticationTimeout: 419,
|
|
28
|
-
misdirectedRequest: 421,
|
|
29
|
-
unprocessableEntity: 422,
|
|
30
|
-
locked: 423,
|
|
31
17
|
failedDependency: 424,
|
|
32
|
-
|
|
33
|
-
upgradeRequired: 426,
|
|
34
|
-
preconditionRequired: 428,
|
|
35
|
-
tooManyRequests: 429,
|
|
36
|
-
requestHeaderFieldsTooLarge: 431,
|
|
37
|
-
retryWith: 449,
|
|
38
|
-
unavailableForLegalReasons: 451,
|
|
39
|
-
clientClosedRequest: 499,
|
|
40
|
-
internalServerError: 500,
|
|
41
|
-
notImplemented: 501,
|
|
42
|
-
badGateway: 502,
|
|
43
|
-
serviceUnavailable: 503,
|
|
18
|
+
forbidden: 403,
|
|
44
19
|
gatewayTimeout: 504,
|
|
20
|
+
gone: 410,
|
|
45
21
|
HTTPVersionNotSupported: 505,
|
|
46
|
-
|
|
22
|
+
imATeapot: 418,
|
|
47
23
|
insufficientStorage: 507,
|
|
24
|
+
internalServerError: 500,
|
|
25
|
+
invalidSSLCertificate: 526,
|
|
26
|
+
lengthRequired: 411,
|
|
27
|
+
locked: 423,
|
|
48
28
|
loopDetected: 508,
|
|
49
|
-
|
|
50
|
-
|
|
29
|
+
methodNotAllowed: 405,
|
|
30
|
+
misdirectedRequest: 421,
|
|
51
31
|
networkAuthenticationRequired: 511,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
32
|
+
notAcceptable: 406,
|
|
33
|
+
notExtended: 510,
|
|
34
|
+
notFound: 404,
|
|
35
|
+
notImplemented: 501,
|
|
55
36
|
originIsUnreachable: 523,
|
|
56
|
-
|
|
37
|
+
payloadTooLarge: 413,
|
|
38
|
+
paymentRequired: 402,
|
|
39
|
+
preconditionFailed: 412,
|
|
40
|
+
preconditionRequired: 428,
|
|
41
|
+
proxyAuthenticationRequired: 407,
|
|
42
|
+
rangeNotSatisfiable: 416,
|
|
43
|
+
requestHeaderFieldsTooLarge: 431,
|
|
44
|
+
requestTimeout: 408,
|
|
45
|
+
retryWith: 449,
|
|
46
|
+
serviceUnavailable: 503,
|
|
57
47
|
SSLHandshakeFailed: 525,
|
|
58
|
-
|
|
48
|
+
tooEarly: 425,
|
|
49
|
+
tooManyRequests: 429,
|
|
50
|
+
unauthorized: 401,
|
|
51
|
+
unavailableForLegalReasons: 451,
|
|
52
|
+
unknownError: 520,
|
|
53
|
+
unprocessableEntity: 422,
|
|
54
|
+
unsupportedMediaType: 415,
|
|
55
|
+
upgradeRequired: 426,
|
|
56
|
+
URITooLong: 414,
|
|
57
|
+
variantAlsoNegotiates: 506,
|
|
58
|
+
webServerIsDown: 521,
|
|
59
59
|
};
|
|
60
60
|
const error = () => {
|
|
61
61
|
const [children] = (useChildren()) || [];
|
|
@@ -64,9 +64,9 @@ const error = () => {
|
|
|
64
64
|
if (!res) {
|
|
65
65
|
throw Error('<error> MUST be in <request>');
|
|
66
66
|
}
|
|
67
|
-
const {
|
|
67
|
+
const { code = 'undefined', status = 520, } = props || {};
|
|
68
68
|
res.statusCode = typeof status === 'string' ? errorStatuses[status] : status;
|
|
69
|
-
res.write(JSONString({
|
|
69
|
+
res.write(JSONString({ data: children, error: code }));
|
|
70
70
|
res.end();
|
|
71
71
|
};
|
|
72
72
|
|
|
@@ -9,57 +9,57 @@ var useResponse = require('../../../hooks/useResponse/useResponse.js');
|
|
|
9
9
|
var JSONString = require('../../../utils/JSONString/JSONString.js');
|
|
10
10
|
|
|
11
11
|
const errorStatuses = {
|
|
12
|
+
aTimeoutOccurred: 524,
|
|
13
|
+
authenticationTimeout: 419,
|
|
14
|
+
badGateway: 502,
|
|
12
15
|
badRequest: 400,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
forbidden: 403,
|
|
16
|
-
notFound: 404,
|
|
17
|
-
methodNotAllowed: 405,
|
|
18
|
-
notAcceptable: 406,
|
|
19
|
-
proxyAuthenticationRequired: 407,
|
|
20
|
-
requestTimeout: 408,
|
|
16
|
+
bandwidthLimitExceeded: 509,
|
|
17
|
+
clientClosedRequest: 499,
|
|
21
18
|
conflict: 409,
|
|
22
|
-
|
|
23
|
-
lengthRequired: 411,
|
|
24
|
-
preconditionFailed: 412,
|
|
25
|
-
payloadTooLarge: 413,
|
|
26
|
-
URITooLong: 414,
|
|
27
|
-
unsupportedMediaType: 415,
|
|
28
|
-
rangeNotSatisfiable: 416,
|
|
19
|
+
connectionTimedOut: 522,
|
|
29
20
|
expectationFailed: 417,
|
|
30
|
-
imATeapot: 418,
|
|
31
|
-
authenticationTimeout: 419,
|
|
32
|
-
misdirectedRequest: 421,
|
|
33
|
-
unprocessableEntity: 422,
|
|
34
|
-
locked: 423,
|
|
35
21
|
failedDependency: 424,
|
|
36
|
-
|
|
37
|
-
upgradeRequired: 426,
|
|
38
|
-
preconditionRequired: 428,
|
|
39
|
-
tooManyRequests: 429,
|
|
40
|
-
requestHeaderFieldsTooLarge: 431,
|
|
41
|
-
retryWith: 449,
|
|
42
|
-
unavailableForLegalReasons: 451,
|
|
43
|
-
clientClosedRequest: 499,
|
|
44
|
-
internalServerError: 500,
|
|
45
|
-
notImplemented: 501,
|
|
46
|
-
badGateway: 502,
|
|
47
|
-
serviceUnavailable: 503,
|
|
22
|
+
forbidden: 403,
|
|
48
23
|
gatewayTimeout: 504,
|
|
24
|
+
gone: 410,
|
|
49
25
|
HTTPVersionNotSupported: 505,
|
|
50
|
-
|
|
26
|
+
imATeapot: 418,
|
|
51
27
|
insufficientStorage: 507,
|
|
28
|
+
internalServerError: 500,
|
|
29
|
+
invalidSSLCertificate: 526,
|
|
30
|
+
lengthRequired: 411,
|
|
31
|
+
locked: 423,
|
|
52
32
|
loopDetected: 508,
|
|
53
|
-
|
|
54
|
-
|
|
33
|
+
methodNotAllowed: 405,
|
|
34
|
+
misdirectedRequest: 421,
|
|
55
35
|
networkAuthenticationRequired: 511,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
36
|
+
notAcceptable: 406,
|
|
37
|
+
notExtended: 510,
|
|
38
|
+
notFound: 404,
|
|
39
|
+
notImplemented: 501,
|
|
59
40
|
originIsUnreachable: 523,
|
|
60
|
-
|
|
41
|
+
payloadTooLarge: 413,
|
|
42
|
+
paymentRequired: 402,
|
|
43
|
+
preconditionFailed: 412,
|
|
44
|
+
preconditionRequired: 428,
|
|
45
|
+
proxyAuthenticationRequired: 407,
|
|
46
|
+
rangeNotSatisfiable: 416,
|
|
47
|
+
requestHeaderFieldsTooLarge: 431,
|
|
48
|
+
requestTimeout: 408,
|
|
49
|
+
retryWith: 449,
|
|
50
|
+
serviceUnavailable: 503,
|
|
61
51
|
SSLHandshakeFailed: 525,
|
|
62
|
-
|
|
52
|
+
tooEarly: 425,
|
|
53
|
+
tooManyRequests: 429,
|
|
54
|
+
unauthorized: 401,
|
|
55
|
+
unavailableForLegalReasons: 451,
|
|
56
|
+
unknownError: 520,
|
|
57
|
+
unprocessableEntity: 422,
|
|
58
|
+
unsupportedMediaType: 415,
|
|
59
|
+
upgradeRequired: 426,
|
|
60
|
+
URITooLong: 414,
|
|
61
|
+
variantAlsoNegotiates: 506,
|
|
62
|
+
webServerIsDown: 521,
|
|
63
63
|
};
|
|
64
64
|
const error = () => {
|
|
65
65
|
const [children] = (jsx.useChildren()) || [];
|
|
@@ -68,9 +68,9 @@ const error = () => {
|
|
|
68
68
|
if (!res) {
|
|
69
69
|
throw Error('<error> MUST be in <request>');
|
|
70
70
|
}
|
|
71
|
-
const {
|
|
71
|
+
const { code = 'undefined', status = 520, } = props || {};
|
|
72
72
|
res.statusCode = typeof status === 'string' ? errorStatuses[status] : status;
|
|
73
|
-
res.write(JSONString.JSONString({
|
|
73
|
+
res.write(JSONString.JSONString({ data: children, error: code }));
|
|
74
74
|
res.end();
|
|
75
75
|
};
|
|
76
76
|
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { type HandlerPlugin } from 'innet';
|
|
3
3
|
import { type IncomingMessage } from 'http';
|
|
4
4
|
export interface ProxyProps {
|
|
5
|
-
to: string;
|
|
6
|
-
secure?: boolean;
|
|
7
5
|
onProxyRes?: (res: IncomingMessage) => void;
|
|
6
|
+
secure?: boolean;
|
|
7
|
+
to: string;
|
|
8
8
|
}
|
|
9
9
|
export declare const proxy: HandlerPlugin;
|
|
@@ -6,7 +6,7 @@ import { useResponse } from '../../../hooks/useResponse/useResponse.es6.js';
|
|
|
6
6
|
import { useThrow } from '../../../hooks/useThrow/useThrow.es6.js';
|
|
7
7
|
|
|
8
8
|
const proxy = () => {
|
|
9
|
-
const {
|
|
9
|
+
const { onProxyRes, secure = false, to, } = useProps();
|
|
10
10
|
const req = useRequest();
|
|
11
11
|
const res = useResponse();
|
|
12
12
|
if (!req || !res) {
|
|
@@ -17,7 +17,7 @@ const proxy = () => {
|
|
|
17
17
|
if (onProxyRes) {
|
|
18
18
|
proxyServer.on('proxyRes', onProxyRes);
|
|
19
19
|
}
|
|
20
|
-
proxyServer.web(req, res, { target: to
|
|
20
|
+
proxyServer.web(req, res, { secure, target: to });
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export { proxy };
|