@innet/server 1.6.6 → 1.7.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/handler/handler.d.ts +3 -2
- package/handler/handler.es6.js +3 -1
- package/handler/handler.js +3 -1
- package/hooks/index.d.ts +1 -0
- package/hooks/index.es6.js +2 -1
- package/hooks/index.js +4 -0
- package/hooks/useAction/index.es6.js +1 -1
- package/hooks/useAction/index.js +1 -0
- package/hooks/useAction/useAction.d.ts +3 -1
- package/hooks/useAction/useAction.es6.js +8 -4
- package/hooks/useAction/useAction.js +7 -2
- package/hooks/useCookies/useCookies.d.ts +1 -1
- package/hooks/useServer/index.d.ts +1 -0
- package/hooks/useServer/index.es6.js +1 -0
- package/hooks/useServer/index.js +10 -0
- package/hooks/useServer/useServer.d.ts +7 -0
- package/hooks/useServer/useServer.es6.js +12 -0
- package/hooks/useServer/useServer.js +17 -0
- package/index.d.ts +0 -2
- package/index.es6.js +5 -3
- package/index.js +11 -6
- package/package.json +1 -1
- package/plugins/access/access.es6.js +4 -3
- package/plugins/access/access.js +4 -3
- package/plugins/action/action.d.ts +10 -0
- package/plugins/action/action.es6.js +38 -0
- package/plugins/action/action.js +60 -0
- package/plugins/action/index.d.ts +1 -0
- package/plugins/action/index.es6.js +1 -0
- package/plugins/action/index.js +9 -0
- package/plugins/cms/cms.es6.js +5 -5
- package/plugins/cms/cms.js +5 -5
- package/plugins/cookie/cookie.es6.js +6 -2
- package/plugins/cookie/cookie.js +6 -2
- package/plugins/error/error.es6.js +7 -2
- package/plugins/error/error.js +7 -2
- package/plugins/file/file.es6.js +8 -4
- package/plugins/file/file.js +8 -4
- package/plugins/formatter/formatter.d.ts +1 -1
- package/plugins/formatter/formatter.es6.js +4 -3
- package/plugins/formatter/formatter.js +4 -3
- package/plugins/header/header.es6.js +7 -3
- package/plugins/header/header.js +7 -3
- package/plugins/index.d.ts +2 -0
- package/plugins/index.es6.js +2 -0
- package/plugins/index.js +4 -0
- package/plugins/parseBody/parseBody.d.ts +1 -1
- package/plugins/parseBody/parseBody.es6.js +3 -2
- package/plugins/parseBody/parseBody.js +3 -2
- package/plugins/proxy/proxy.es6.js +7 -2
- package/plugins/proxy/proxy.js +7 -2
- package/plugins/redirect/redirect.es6.js +7 -3
- package/plugins/redirect/redirect.js +7 -3
- package/plugins/router/router.d.ts +1 -1
- package/plugins/router/router.es6.js +4 -3
- package/plugins/router/router.js +4 -3
- package/plugins/server/server.d.ts +22 -0
- package/plugins/server/server.es6.js +43 -0
- package/plugins/server/server.js +55 -0
- package/plugins/success/success.es6.js +7 -3
- package/plugins/success/success.js +7 -3
- package/plugins/validation/validation.d.ts +1 -1
- package/plugins/validation/validation.es6.js +4 -3
- package/plugins/validation/validation.js +4 -3
- package/{action → utils/action}/Action/Action.d.ts +0 -1
- package/{action → utils/action}/Action/Action.es6.js +2 -4
- package/{action → utils/action}/Action/Action.js +1 -4
- package/utils/action/Action/index.es6.js +1 -0
- package/{action → utils/action}/Action/index.js +0 -1
- package/utils/action/index.es6.js +1 -0
- package/{action → utils/action}/index.js +0 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.es6.js +1 -0
- package/utils/index.js +5 -0
- package/action/Action/index.es6.js +0 -1
- package/action/index.es6.js +0 -1
- package/server/server.d.ts +0 -20
- package/server/server.es6.js +0 -69
- package/server/server.js +0 -97
- /package/{server → plugins/server}/index.d.ts +0 -0
- /package/{server → plugins/server}/index.es6.js +0 -0
- /package/{server → plugins/server}/index.js +0 -0
- /package/{action → utils/action}/Action/index.d.ts +0 -0
- /package/{action → utils/action}/index.d.ts +0 -0
|
@@ -6,15 +6,13 @@ var tslib = require('tslib');
|
|
|
6
6
|
var utils = require('@cantinc/utils');
|
|
7
7
|
var cookie = require('cookie');
|
|
8
8
|
var multiparty = require('multiparty');
|
|
9
|
-
var parseSearch = require('../../
|
|
10
|
-
require('qs');
|
|
9
|
+
var parseSearch = require('../../parseSearch/parseSearch.js');
|
|
11
10
|
|
|
12
11
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
12
|
|
|
14
13
|
var cookie__default = /*#__PURE__*/_interopDefaultLegacy(cookie);
|
|
15
14
|
var multiparty__default = /*#__PURE__*/_interopDefaultLegacy(multiparty);
|
|
16
15
|
|
|
17
|
-
var ACTION = Symbol('Action');
|
|
18
16
|
var URL_PARSER = /^(?<path>[^?]+)(\?(?<search>.*))?/;
|
|
19
17
|
var KEY_FIELD = /^(?<field>[^[]+)(?<rest>.*)$/;
|
|
20
18
|
var KEY_KEYS = /^\[(?<key>[^\]]+)\](?<rest>.*)$/;
|
|
@@ -161,7 +159,6 @@ var Action = /** @class */ (function () {
|
|
|
161
159
|
return Action;
|
|
162
160
|
}());
|
|
163
161
|
|
|
164
|
-
exports.ACTION = ACTION;
|
|
165
162
|
exports.Action = Action;
|
|
166
163
|
exports.KEY_FIELD = KEY_FIELD;
|
|
167
164
|
exports.KEY_KEYS = KEY_KEYS;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Action, KEY_FIELD, KEY_KEYS, URL_PARSER } from './Action.es6.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Action, KEY_FIELD, KEY_KEYS, URL_PARSER } from './Action/Action.es6.js';
|
package/utils/index.d.ts
CHANGED
package/utils/index.es6.js
CHANGED
package/utils/index.js
CHANGED
|
@@ -4,8 +4,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var parseSearch = require('./parseSearch/parseSearch.js');
|
|
6
6
|
var stringifySearch = require('./stringifySearch/stringifySearch.js');
|
|
7
|
+
var Action = require('./action/Action/Action.js');
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
exports.parseSearch = parseSearch.parseSearch;
|
|
11
12
|
exports.stringifySearch = stringifySearch.stringifySearch;
|
|
13
|
+
exports.Action = Action.Action;
|
|
14
|
+
exports.KEY_FIELD = Action.KEY_FIELD;
|
|
15
|
+
exports.KEY_KEYS = Action.KEY_KEYS;
|
|
16
|
+
exports.URL_PARSER = Action.URL_PARSER;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ACTION, Action, KEY_FIELD, KEY_KEYS, URL_PARSER } from './Action.es6.js';
|
package/action/index.es6.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ACTION, Action, KEY_FIELD, KEY_KEYS, URL_PARSER } from './Action/Action.es6.js';
|
package/server/server.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Handler } from 'innet';
|
|
2
|
-
import { Action, ActionParams } from '../action';
|
|
3
|
-
export interface SSL {
|
|
4
|
-
cert: string;
|
|
5
|
-
key: string;
|
|
6
|
-
}
|
|
7
|
-
export interface ServerProps {
|
|
8
|
-
actionParams?: ActionParams;
|
|
9
|
-
port?: number;
|
|
10
|
-
ssl?: SSL;
|
|
11
|
-
unknownError?: string;
|
|
12
|
-
onStart?: (url: string) => any;
|
|
13
|
-
onRequest?: (action: Action) => any;
|
|
14
|
-
onError?: (e: Error, action?: Action) => any;
|
|
15
|
-
onDestroy?: () => any;
|
|
16
|
-
}
|
|
17
|
-
export declare function server({ props, children }: {
|
|
18
|
-
props?: ServerProps;
|
|
19
|
-
children: any;
|
|
20
|
-
}, handler: Handler): Promise<unknown>;
|
package/server/server.es6.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { __awaiter } from 'tslib';
|
|
2
|
-
import innet from 'innet';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import http from 'http';
|
|
5
|
-
import http2 from 'https';
|
|
6
|
-
import { onDestroy } from 'watch-state';
|
|
7
|
-
import { ACTION, Action } from '../action/Action/Action.es6.js';
|
|
8
|
-
import { CONTINUE } from '../constants.es6.js';
|
|
9
|
-
|
|
10
|
-
const isInvalidPath = require('is-invalid-path');
|
|
11
|
-
function server({ props = {}, children }, handler) {
|
|
12
|
-
const { env } = process;
|
|
13
|
-
let { ssl: { key = env.SSL_KEY, cert = env.SSL_CRT } = {}, actionParams } = props;
|
|
14
|
-
if (!isInvalidPath(key)) {
|
|
15
|
-
key = fs.readFileSync(key).toString();
|
|
16
|
-
}
|
|
17
|
-
if (!isInvalidPath(cert)) {
|
|
18
|
-
cert = fs.readFileSync(cert).toString();
|
|
19
|
-
}
|
|
20
|
-
const https = Boolean(key && cert);
|
|
21
|
-
const { port = env.PORT || (https ? 442 : 80), unknownError = '', onStart, onError, onRequest } = props;
|
|
22
|
-
const server = https ? http2.createServer({ key, cert }) : http.createServer();
|
|
23
|
-
onDestroy(() => {
|
|
24
|
-
var _a;
|
|
25
|
-
(_a = props.onDestroy) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
26
|
-
server.close();
|
|
27
|
-
});
|
|
28
|
-
server.on('request', (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
const childHandler = Object.create(handler);
|
|
30
|
-
childHandler[ACTION] = new Action(req, res, actionParams);
|
|
31
|
-
if (onRequest) {
|
|
32
|
-
yield onRequest(childHandler[ACTION]);
|
|
33
|
-
}
|
|
34
|
-
if (children) {
|
|
35
|
-
try {
|
|
36
|
-
const result = yield innet(children, childHandler);
|
|
37
|
-
if (result === CONTINUE) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (typeof result === 'string') {
|
|
41
|
-
res.write(result);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
res.statusCode = 520;
|
|
46
|
-
onError === null || onError === void 0 ? void 0 : onError(e, childHandler[ACTION]);
|
|
47
|
-
res.write(unknownError);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
res.end();
|
|
51
|
-
}));
|
|
52
|
-
let res, rej;
|
|
53
|
-
const promise = new Promise((resolve, reject) => {
|
|
54
|
-
res = resolve;
|
|
55
|
-
rej = reject;
|
|
56
|
-
});
|
|
57
|
-
server.on('error', e => {
|
|
58
|
-
rej(e);
|
|
59
|
-
onError === null || onError === void 0 ? void 0 : onError(e);
|
|
60
|
-
});
|
|
61
|
-
server.listen(port, () => {
|
|
62
|
-
const url = `http${https ? 's' : ''}://localhost:${port}`;
|
|
63
|
-
onStart === null || onStart === void 0 ? void 0 : onStart(url);
|
|
64
|
-
res(url);
|
|
65
|
-
});
|
|
66
|
-
return promise;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export { server };
|
package/server/server.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var tslib = require('tslib');
|
|
6
|
-
var innet = require('innet');
|
|
7
|
-
var fs = require('fs');
|
|
8
|
-
var http = require('http');
|
|
9
|
-
var http2 = require('https');
|
|
10
|
-
var watchState = require('watch-state');
|
|
11
|
-
var Action = require('../action/Action/Action.js');
|
|
12
|
-
var constants = require('../constants.js');
|
|
13
|
-
|
|
14
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
|
-
|
|
16
|
-
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
17
|
-
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
18
|
-
var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
|
|
19
|
-
var http2__default = /*#__PURE__*/_interopDefaultLegacy(http2);
|
|
20
|
-
|
|
21
|
-
var isInvalidPath = require('is-invalid-path');
|
|
22
|
-
function server(_a, handler) {
|
|
23
|
-
var _this = this;
|
|
24
|
-
var _b = _a.props, props = _b === void 0 ? {} : _b, children = _a.children;
|
|
25
|
-
var env = process.env;
|
|
26
|
-
var _c = props.ssl, _d = _c === void 0 ? {} : _c, _e = _d.key, key = _e === void 0 ? env.SSL_KEY : _e, _f = _d.cert, cert = _f === void 0 ? env.SSL_CRT : _f, actionParams = props.actionParams;
|
|
27
|
-
if (!isInvalidPath(key)) {
|
|
28
|
-
key = fs__default["default"].readFileSync(key).toString();
|
|
29
|
-
}
|
|
30
|
-
if (!isInvalidPath(cert)) {
|
|
31
|
-
cert = fs__default["default"].readFileSync(cert).toString();
|
|
32
|
-
}
|
|
33
|
-
var https = Boolean(key && cert);
|
|
34
|
-
var _g = props.port, port = _g === void 0 ? env.PORT || (https ? 442 : 80) : _g, _h = props.unknownError, unknownError = _h === void 0 ? '' : _h, onStart = props.onStart, onError = props.onError, onRequest = props.onRequest;
|
|
35
|
-
var server = https ? http2__default["default"].createServer({ key: key, cert: cert }) : http__default["default"].createServer();
|
|
36
|
-
watchState.onDestroy(function () {
|
|
37
|
-
var _a;
|
|
38
|
-
(_a = props.onDestroy) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
39
|
-
server.close();
|
|
40
|
-
});
|
|
41
|
-
server.on('request', function (req, res) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
42
|
-
var childHandler, result, e_1;
|
|
43
|
-
return tslib.__generator(this, function (_a) {
|
|
44
|
-
switch (_a.label) {
|
|
45
|
-
case 0:
|
|
46
|
-
childHandler = Object.create(handler);
|
|
47
|
-
childHandler[Action.ACTION] = new Action.Action(req, res, actionParams);
|
|
48
|
-
if (!onRequest) return [3 /*break*/, 2];
|
|
49
|
-
return [4 /*yield*/, onRequest(childHandler[Action.ACTION])];
|
|
50
|
-
case 1:
|
|
51
|
-
_a.sent();
|
|
52
|
-
_a.label = 2;
|
|
53
|
-
case 2:
|
|
54
|
-
if (!children) return [3 /*break*/, 6];
|
|
55
|
-
_a.label = 3;
|
|
56
|
-
case 3:
|
|
57
|
-
_a.trys.push([3, 5, , 6]);
|
|
58
|
-
return [4 /*yield*/, innet__default["default"](children, childHandler)];
|
|
59
|
-
case 4:
|
|
60
|
-
result = _a.sent();
|
|
61
|
-
if (result === constants.CONTINUE) {
|
|
62
|
-
return [2 /*return*/];
|
|
63
|
-
}
|
|
64
|
-
if (typeof result === 'string') {
|
|
65
|
-
res.write(result);
|
|
66
|
-
}
|
|
67
|
-
return [3 /*break*/, 6];
|
|
68
|
-
case 5:
|
|
69
|
-
e_1 = _a.sent();
|
|
70
|
-
res.statusCode = 520;
|
|
71
|
-
onError === null || onError === void 0 ? void 0 : onError(e_1, childHandler[Action.ACTION]);
|
|
72
|
-
res.write(unknownError);
|
|
73
|
-
return [3 /*break*/, 6];
|
|
74
|
-
case 6:
|
|
75
|
-
res.end();
|
|
76
|
-
return [2 /*return*/];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}); });
|
|
80
|
-
var res, rej;
|
|
81
|
-
var promise = new Promise(function (resolve, reject) {
|
|
82
|
-
res = resolve;
|
|
83
|
-
rej = reject;
|
|
84
|
-
});
|
|
85
|
-
server.on('error', function (e) {
|
|
86
|
-
rej(e);
|
|
87
|
-
onError === null || onError === void 0 ? void 0 : onError(e);
|
|
88
|
-
});
|
|
89
|
-
server.listen(port, function () {
|
|
90
|
-
var url = "http".concat(https ? 's' : '', "://localhost:").concat(port);
|
|
91
|
-
onStart === null || onStart === void 0 ? void 0 : onStart(url);
|
|
92
|
-
res(url);
|
|
93
|
-
});
|
|
94
|
-
return promise;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
exports.server = server;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|