@innet/server 1.6.6 → 1.7.1
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/README.md +213 -129
- 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 +6 -4
- package/index.js +12 -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 +3 -1
- package/plugins/index.js +5 -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/index.es6.js +1 -1
- package/plugins/proxy/index.js +1 -0
- package/plugins/proxy/proxy.d.ts +5 -6
- package/plugins/proxy/proxy.es6.js +8 -3
- package/plugins/proxy/proxy.js +8 -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
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import innet from 'innet';
|
|
2
|
-
import {
|
|
2
|
+
import { actionContext } from '../../hooks/useAction/useAction.es6.js';
|
|
3
|
+
import '../../hooks/useServer/useServer.es6.js';
|
|
3
4
|
|
|
4
5
|
function formatter({ props, children }, handler) {
|
|
5
|
-
const action = handler
|
|
6
|
+
const action = actionContext.get(handler);
|
|
6
7
|
if (!action) {
|
|
7
|
-
throw Error('
|
|
8
|
+
throw Error('Use <formatter> inside <action>');
|
|
8
9
|
}
|
|
9
10
|
const { map, resource = 'body' } = props;
|
|
10
11
|
const run = () => {
|
|
@@ -4,7 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var tslib = require('tslib');
|
|
6
6
|
var innet = require('innet');
|
|
7
|
-
var
|
|
7
|
+
var useAction = require('../../hooks/useAction/useAction.js');
|
|
8
|
+
require('../../hooks/useServer/useServer.js');
|
|
8
9
|
|
|
9
10
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
11
|
|
|
@@ -12,9 +13,9 @@ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
|
12
13
|
|
|
13
14
|
function formatter(_a, handler) {
|
|
14
15
|
var props = _a.props, children = _a.children;
|
|
15
|
-
var action = handler
|
|
16
|
+
var action = useAction.actionContext.get(handler);
|
|
16
17
|
if (!action) {
|
|
17
|
-
throw Error('
|
|
18
|
+
throw Error('Use <formatter> inside <action>');
|
|
18
19
|
}
|
|
19
20
|
var map = props.map, _b = props.resource, resource = _b === void 0 ? 'body' : _b;
|
|
20
21
|
var run = function () {
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import innet from 'innet';
|
|
2
|
-
import {
|
|
2
|
+
import { actionContext } from '../../hooks/useAction/useAction.es6.js';
|
|
3
|
+
import '../../hooks/useServer/useServer.es6.js';
|
|
3
4
|
|
|
4
5
|
function header({ props: { name, value }, children }, handler) {
|
|
5
|
-
const
|
|
6
|
-
|
|
6
|
+
const action = actionContext.get(handler);
|
|
7
|
+
if (!action) {
|
|
8
|
+
throw Error('Use <header> inside <action>');
|
|
9
|
+
}
|
|
10
|
+
action.res.setHeader(name, value);
|
|
7
11
|
return innet(children, handler);
|
|
8
12
|
}
|
|
9
13
|
|
package/plugins/header/header.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var innet = require('innet');
|
|
6
|
-
var
|
|
6
|
+
var useAction = require('../../hooks/useAction/useAction.js');
|
|
7
|
+
require('../../hooks/useServer/useServer.js');
|
|
7
8
|
|
|
8
9
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
10
|
|
|
@@ -11,8 +12,11 @@ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
|
11
12
|
|
|
12
13
|
function header(_a, handler) {
|
|
13
14
|
var _b = _a.props, name = _b.name, value = _b.value, children = _a.children;
|
|
14
|
-
var
|
|
15
|
-
|
|
15
|
+
var action = useAction.actionContext.get(handler);
|
|
16
|
+
if (!action) {
|
|
17
|
+
throw Error('Use <header> inside <action>');
|
|
18
|
+
}
|
|
19
|
+
action.res.setHeader(name, value);
|
|
16
20
|
return innet__default["default"](children, handler);
|
|
17
21
|
}
|
|
18
22
|
|
package/plugins/index.d.ts
CHANGED
package/plugins/index.es6.js
CHANGED
|
@@ -5,9 +5,11 @@ export { success, successStatuses } from './success/success.es6.js';
|
|
|
5
5
|
export { error, errorStatuses } from './error/error.es6.js';
|
|
6
6
|
export { cms } from './cms/cms.es6.js';
|
|
7
7
|
export { file } from './file/file.es6.js';
|
|
8
|
-
export { proxy } from './proxy/proxy.es6.js';
|
|
8
|
+
export { proxy, proxyServer } from './proxy/proxy.es6.js';
|
|
9
9
|
export { redirect, redirectStatuses } from './redirect/redirect.es6.js';
|
|
10
10
|
export { validation, validationContext } from './validation/validation.es6.js';
|
|
11
11
|
export { formatter } from './formatter/formatter.es6.js';
|
|
12
12
|
export { access, accessContext } from './access/access.es6.js';
|
|
13
13
|
export { parseBody } from './parseBody/parseBody.es6.js';
|
|
14
|
+
export { server } from './server/server.es6.js';
|
|
15
|
+
export { action } from './action/action.es6.js';
|
package/plugins/index.js
CHANGED
|
@@ -15,6 +15,8 @@ var validation = require('./validation/validation.js');
|
|
|
15
15
|
var formatter = require('./formatter/formatter.js');
|
|
16
16
|
var access = require('./access/access.js');
|
|
17
17
|
var parseBody = require('./parseBody/parseBody.js');
|
|
18
|
+
var server = require('./server/server.js');
|
|
19
|
+
var action = require('./action/action.js');
|
|
18
20
|
|
|
19
21
|
|
|
20
22
|
|
|
@@ -31,6 +33,7 @@ exports.errorStatuses = error.errorStatuses;
|
|
|
31
33
|
exports.cms = cms.cms;
|
|
32
34
|
exports.file = file.file;
|
|
33
35
|
exports.proxy = proxy.proxy;
|
|
36
|
+
exports.proxyServer = proxy.proxyServer;
|
|
34
37
|
exports.redirect = redirect.redirect;
|
|
35
38
|
exports.redirectStatuses = redirect.redirectStatuses;
|
|
36
39
|
exports.validation = validation.validation;
|
|
@@ -39,3 +42,5 @@ exports.formatter = formatter.formatter;
|
|
|
39
42
|
exports.access = access.access;
|
|
40
43
|
exports.accessContext = access.accessContext;
|
|
41
44
|
exports.parseBody = parseBody.parseBody;
|
|
45
|
+
exports.server = server.server;
|
|
46
|
+
exports.action = action.action;
|
|
@@ -4,4 +4,4 @@ export interface ParseBodyJsxElement {
|
|
|
4
4
|
props: ParseBodyProps;
|
|
5
5
|
children?: any;
|
|
6
6
|
}
|
|
7
|
-
export declare function parseBody({ props, children }: ParseBodyJsxElement, handler: any): any
|
|
7
|
+
export declare function parseBody({ props, children }: ParseBodyJsxElement, handler: any): Promise<any>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import innet from 'innet';
|
|
2
|
-
import {
|
|
2
|
+
import { actionContext } from '../../hooks/useAction/useAction.es6.js';
|
|
3
|
+
import '../../hooks/useServer/useServer.es6.js';
|
|
3
4
|
|
|
4
5
|
function parseBody({ props, children }, handler) {
|
|
5
|
-
return handler
|
|
6
|
+
return actionContext.get(handler).parseBody().then(() => innet(children, handler));
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
export { parseBody };
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var innet = require('innet');
|
|
6
|
-
var
|
|
6
|
+
var useAction = require('../../hooks/useAction/useAction.js');
|
|
7
|
+
require('../../hooks/useServer/useServer.js');
|
|
7
8
|
|
|
8
9
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
10
|
|
|
@@ -11,7 +12,7 @@ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
|
11
12
|
|
|
12
13
|
function parseBody(_a, handler) {
|
|
13
14
|
_a.props; var children = _a.children;
|
|
14
|
-
return handler
|
|
15
|
+
return useAction.actionContext.get(handler).parseBody().then(function () { return innet__default["default"](children, handler); });
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
exports.parseBody = parseBody;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { proxy } from './proxy.es6.js';
|
|
1
|
+
export { proxy, proxyServer } from './proxy.es6.js';
|
package/plugins/proxy/index.js
CHANGED
package/plugins/proxy/proxy.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Handler } from 'innet';
|
|
2
|
+
import { JSXElement } from '@innet/jsx';
|
|
3
|
+
import httpProxy from 'http-proxy';
|
|
2
4
|
export interface ProxyProps {
|
|
3
5
|
to: string;
|
|
6
|
+
secure?: boolean;
|
|
4
7
|
}
|
|
5
|
-
export declare
|
|
6
|
-
|
|
7
|
-
to: any;
|
|
8
|
-
secure?: boolean;
|
|
9
|
-
};
|
|
10
|
-
}, handler: Handler): symbol;
|
|
8
|
+
export declare const proxyServer: httpProxy;
|
|
9
|
+
export declare function proxy({ props: { to, secure } }: JSXElement<string, ProxyProps>, handler: Handler): symbol;
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import httpProxy from 'http-proxy';
|
|
2
|
-
import { ACTION } from '../../action/Action/Action.es6.js';
|
|
3
2
|
import { CONTINUE } from '../../constants.es6.js';
|
|
3
|
+
import { actionContext } from '../../hooks/useAction/useAction.es6.js';
|
|
4
|
+
import '../../hooks/useServer/useServer.es6.js';
|
|
4
5
|
|
|
5
6
|
const proxyServer = httpProxy.createProxyServer({});
|
|
6
7
|
function proxy({ props: { to, secure = false } }, handler) {
|
|
7
|
-
const
|
|
8
|
+
const action = actionContext.get(handler);
|
|
9
|
+
if (!action) {
|
|
10
|
+
throw Error('Use <proxy> inside <action>');
|
|
11
|
+
}
|
|
12
|
+
const { req, res } = action;
|
|
8
13
|
delete req.headers.host;
|
|
9
14
|
proxyServer.web(req, res, { target: to, secure });
|
|
10
15
|
return CONTINUE;
|
|
11
16
|
}
|
|
12
17
|
|
|
13
|
-
export { proxy };
|
|
18
|
+
export { proxy, proxyServer };
|
package/plugins/proxy/proxy.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var httpProxy = require('http-proxy');
|
|
6
|
-
var Action = require('../../action/Action/Action.js');
|
|
7
6
|
var constants = require('../../constants.js');
|
|
7
|
+
var useAction = require('../../hooks/useAction/useAction.js');
|
|
8
|
+
require('../../hooks/useServer/useServer.js');
|
|
8
9
|
|
|
9
10
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
11
|
|
|
@@ -13,10 +14,15 @@ var httpProxy__default = /*#__PURE__*/_interopDefaultLegacy(httpProxy);
|
|
|
13
14
|
var proxyServer = httpProxy__default["default"].createProxyServer({});
|
|
14
15
|
function proxy(_a, handler) {
|
|
15
16
|
var _b = _a.props, to = _b.to, _c = _b.secure, secure = _c === void 0 ? false : _c;
|
|
16
|
-
var
|
|
17
|
+
var action = useAction.actionContext.get(handler);
|
|
18
|
+
if (!action) {
|
|
19
|
+
throw Error('Use <proxy> inside <action>');
|
|
20
|
+
}
|
|
21
|
+
var req = action.req, res = action.res;
|
|
17
22
|
delete req.headers.host;
|
|
18
23
|
proxyServer.web(req, res, { target: to, secure: secure });
|
|
19
24
|
return constants.CONTINUE;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
exports.proxy = proxy;
|
|
28
|
+
exports.proxyServer = proxyServer;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { actionContext } from '../../hooks/useAction/useAction.es6.js';
|
|
2
|
+
import '../../hooks/useServer/useServer.es6.js';
|
|
2
3
|
|
|
3
4
|
const redirectStatuses = {
|
|
4
5
|
multipleChoices: 300,
|
|
@@ -19,9 +20,12 @@ function customEncode(url) {
|
|
|
19
20
|
return encodeURI(url.replaceAll('%20', ' '));
|
|
20
21
|
}
|
|
21
22
|
function redirect({ props, children }, handler) {
|
|
22
|
-
const
|
|
23
|
+
const action = actionContext.get(handler);
|
|
24
|
+
if (!action) {
|
|
25
|
+
throw Error('Use <redirect> inside <action>');
|
|
26
|
+
}
|
|
23
27
|
const { to, status = 301, encode } = props;
|
|
24
|
-
res.writeHead(getStatus(status), {
|
|
28
|
+
action.res.writeHead(getStatus(status), {
|
|
25
29
|
location: encode ? customEncode(to) : to,
|
|
26
30
|
});
|
|
27
31
|
return null;
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var useAction = require('../../hooks/useAction/useAction.js');
|
|
6
|
+
require('../../hooks/useServer/useServer.js');
|
|
6
7
|
|
|
7
8
|
var redirectStatuses = {
|
|
8
9
|
multipleChoices: 300,
|
|
@@ -24,9 +25,12 @@ function customEncode(url) {
|
|
|
24
25
|
}
|
|
25
26
|
function redirect(_a, handler) {
|
|
26
27
|
var props = _a.props; _a.children;
|
|
27
|
-
var
|
|
28
|
+
var action = useAction.actionContext.get(handler);
|
|
29
|
+
if (!action) {
|
|
30
|
+
throw Error('Use <redirect> inside <action>');
|
|
31
|
+
}
|
|
28
32
|
var to = props.to, _b = props.status, status = _b === void 0 ? 301 : _b, encode = props.encode;
|
|
29
|
-
res.writeHead(getStatus(status), {
|
|
33
|
+
action.res.writeHead(getStatus(status), {
|
|
30
34
|
location: encode ? customEncode(to) : to,
|
|
31
35
|
});
|
|
32
36
|
return null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import innet from 'innet';
|
|
2
2
|
import { useHandler } from '@innet/jsx';
|
|
3
|
-
import {
|
|
3
|
+
import { actionContext } from '../../hooks/useAction/useAction.es6.js';
|
|
4
|
+
import '../../hooks/useServer/useServer.es6.js';
|
|
4
5
|
|
|
5
6
|
function getMatchReg(props) {
|
|
6
7
|
const { ish, path } = props;
|
|
@@ -16,9 +17,9 @@ function router({ props, children }, handler) {
|
|
|
16
17
|
return;
|
|
17
18
|
if (!props)
|
|
18
19
|
return children;
|
|
19
|
-
const action = handler
|
|
20
|
+
const action = actionContext.get(handler);
|
|
20
21
|
if (!action) {
|
|
21
|
-
throw Error('
|
|
22
|
+
throw Error('Use <router> inside <action>');
|
|
22
23
|
}
|
|
23
24
|
const { req, path } = action;
|
|
24
25
|
if (props.method && props.method !== req.method) {
|
package/plugins/router/router.js
CHANGED
|
@@ -4,7 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var innet = require('innet');
|
|
6
6
|
var jsx = require('@innet/jsx');
|
|
7
|
-
var
|
|
7
|
+
var useAction = require('../../hooks/useAction/useAction.js');
|
|
8
|
+
require('../../hooks/useServer/useServer.js');
|
|
8
9
|
|
|
9
10
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
11
|
|
|
@@ -25,9 +26,9 @@ function router(_a, handler) {
|
|
|
25
26
|
return;
|
|
26
27
|
if (!props)
|
|
27
28
|
return children;
|
|
28
|
-
var action = handler
|
|
29
|
+
var action = useAction.actionContext.get(handler);
|
|
29
30
|
if (!action) {
|
|
30
|
-
throw Error('
|
|
31
|
+
throw Error('Use <router> inside <action>');
|
|
31
32
|
}
|
|
32
33
|
var req = action.req, path = action.path;
|
|
33
34
|
if (props.method && props.method !== req.method) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Handler } from 'innet';
|
|
4
|
+
import http from 'http';
|
|
5
|
+
import http2 from 'https';
|
|
6
|
+
import { Request, Response } from '../../utils';
|
|
7
|
+
export interface SSL {
|
|
8
|
+
cert: string;
|
|
9
|
+
key: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ServerProps {
|
|
12
|
+
port?: number;
|
|
13
|
+
ssl?: SSL;
|
|
14
|
+
onStart?: (url: string) => any;
|
|
15
|
+
onRequest?: (req: Request, res: Response) => any;
|
|
16
|
+
onError?: (e: Error) => any;
|
|
17
|
+
onDestroy?: () => any;
|
|
18
|
+
}
|
|
19
|
+
export declare function server({ props, children }: {
|
|
20
|
+
props?: ServerProps;
|
|
21
|
+
children: any;
|
|
22
|
+
}, handler: Handler): http2.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import innet from 'innet';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import http from 'http';
|
|
4
|
+
import http2 from 'https';
|
|
5
|
+
import { onDestroy } from 'watch-state';
|
|
6
|
+
import '../../hooks/useAction/useAction.es6.js';
|
|
7
|
+
import { serverContext } from '../../hooks/useServer/useServer.es6.js';
|
|
8
|
+
|
|
9
|
+
const isInvalidPath = require('is-invalid-path');
|
|
10
|
+
function server({ props = {}, children }, handler) {
|
|
11
|
+
const { env } = process;
|
|
12
|
+
let { ssl: { key = env.SSL_KEY, cert = env.SSL_CRT } = {} } = props;
|
|
13
|
+
const childHandler = Object.create(handler);
|
|
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), onStart, onError, onRequest } = props;
|
|
22
|
+
const server = https ? http2.createServer({ key, cert }) : http.createServer();
|
|
23
|
+
childHandler[serverContext.key] = server;
|
|
24
|
+
onDestroy(() => {
|
|
25
|
+
var _a;
|
|
26
|
+
(_a = props.onDestroy) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
27
|
+
server.close();
|
|
28
|
+
});
|
|
29
|
+
if (onError) {
|
|
30
|
+
server.on('error', onError);
|
|
31
|
+
}
|
|
32
|
+
if (onRequest) {
|
|
33
|
+
server.on('request', onRequest);
|
|
34
|
+
}
|
|
35
|
+
innet(children, childHandler);
|
|
36
|
+
server.listen(port, () => {
|
|
37
|
+
const url = `http${https ? 's' : ''}://localhost:${port}`;
|
|
38
|
+
onStart === null || onStart === void 0 ? void 0 : onStart(url);
|
|
39
|
+
});
|
|
40
|
+
return server;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { server };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var innet = require('innet');
|
|
6
|
+
var fs = require('fs');
|
|
7
|
+
var http = require('http');
|
|
8
|
+
var http2 = require('https');
|
|
9
|
+
var watchState = require('watch-state');
|
|
10
|
+
require('../../hooks/useAction/useAction.js');
|
|
11
|
+
var useServer = require('../../hooks/useServer/useServer.js');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
16
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
17
|
+
var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
|
|
18
|
+
var http2__default = /*#__PURE__*/_interopDefaultLegacy(http2);
|
|
19
|
+
|
|
20
|
+
var isInvalidPath = require('is-invalid-path');
|
|
21
|
+
function server(_a, handler) {
|
|
22
|
+
var _b = _a.props, props = _b === void 0 ? {} : _b, children = _a.children;
|
|
23
|
+
var env = process.env;
|
|
24
|
+
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;
|
|
25
|
+
var childHandler = Object.create(handler);
|
|
26
|
+
if (!isInvalidPath(key)) {
|
|
27
|
+
key = fs__default["default"].readFileSync(key).toString();
|
|
28
|
+
}
|
|
29
|
+
if (!isInvalidPath(cert)) {
|
|
30
|
+
cert = fs__default["default"].readFileSync(cert).toString();
|
|
31
|
+
}
|
|
32
|
+
var https = Boolean(key && cert);
|
|
33
|
+
var _g = props.port, port = _g === void 0 ? env.PORT || (https ? 442 : 80) : _g, onStart = props.onStart, onError = props.onError, onRequest = props.onRequest;
|
|
34
|
+
var server = https ? http2__default["default"].createServer({ key: key, cert: cert }) : http__default["default"].createServer();
|
|
35
|
+
childHandler[useServer.serverContext.key] = server;
|
|
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
|
+
if (onError) {
|
|
42
|
+
server.on('error', onError);
|
|
43
|
+
}
|
|
44
|
+
if (onRequest) {
|
|
45
|
+
server.on('request', onRequest);
|
|
46
|
+
}
|
|
47
|
+
innet__default["default"](children, childHandler);
|
|
48
|
+
server.listen(port, function () {
|
|
49
|
+
var url = "http".concat(https ? 's' : '', "://localhost:").concat(port);
|
|
50
|
+
onStart === null || onStart === void 0 ? void 0 : onStart(url);
|
|
51
|
+
});
|
|
52
|
+
return server;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
exports.server = server;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import innet from 'innet';
|
|
2
|
-
import {
|
|
2
|
+
import { actionContext } from '../../hooks/useAction/useAction.es6.js';
|
|
3
|
+
import '../../hooks/useServer/useServer.es6.js';
|
|
3
4
|
|
|
4
5
|
const successStatuses = {
|
|
5
6
|
ok: 200,
|
|
@@ -13,9 +14,12 @@ const successStatuses = {
|
|
|
13
14
|
alreadyReported: 208,
|
|
14
15
|
};
|
|
15
16
|
function success({ props, children }, handler) {
|
|
16
|
-
const
|
|
17
|
+
const action = actionContext.get(handler);
|
|
18
|
+
if (!action) {
|
|
19
|
+
throw Error('Use <success> inside <action>');
|
|
20
|
+
}
|
|
17
21
|
const status = props === null || props === void 0 ? void 0 : props.status;
|
|
18
|
-
res.statusCode = status
|
|
22
|
+
action.res.statusCode = status
|
|
19
23
|
? successStatuses[status] || status
|
|
20
24
|
: children
|
|
21
25
|
? 200
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var innet = require('innet');
|
|
6
|
-
var
|
|
6
|
+
var useAction = require('../../hooks/useAction/useAction.js');
|
|
7
|
+
require('../../hooks/useServer/useServer.js');
|
|
7
8
|
|
|
8
9
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
10
|
|
|
@@ -22,9 +23,12 @@ var successStatuses = {
|
|
|
22
23
|
};
|
|
23
24
|
function success(_a, handler) {
|
|
24
25
|
var props = _a.props, children = _a.children;
|
|
25
|
-
var
|
|
26
|
+
var action = useAction.actionContext.get(handler);
|
|
27
|
+
if (!action) {
|
|
28
|
+
throw Error('Use <success> inside <action>');
|
|
29
|
+
}
|
|
26
30
|
var status = props === null || props === void 0 ? void 0 : props.status;
|
|
27
|
-
res.statusCode = status
|
|
31
|
+
action.res.statusCode = status
|
|
28
32
|
? successStatuses[status] || status
|
|
29
33
|
: children
|
|
30
34
|
? 200
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ValidationMap, ValidationResponse } from '@cantinc/utils';
|
|
2
2
|
import { Context } from '@innet/jsx';
|
|
3
|
-
import { Resources } from '../../
|
|
3
|
+
import { Resources } from '../../utils';
|
|
4
4
|
export interface ValidationProps<T> {
|
|
5
5
|
map: ValidationMap<T>;
|
|
6
6
|
resource?: Resources;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import innet from 'innet';
|
|
2
2
|
import { validation as validation$1 } from '@cantinc/utils';
|
|
3
3
|
import { Context } from '@innet/jsx';
|
|
4
|
-
import {
|
|
4
|
+
import { actionContext } from '../../hooks/useAction/useAction.es6.js';
|
|
5
|
+
import '../../hooks/useServer/useServer.es6.js';
|
|
5
6
|
|
|
6
7
|
const validationContext = new Context({});
|
|
7
8
|
function validation({ props, children }, handler) {
|
|
8
|
-
const action = handler
|
|
9
|
+
const action = actionContext.get(handler);
|
|
9
10
|
if (!action) {
|
|
10
|
-
throw Error('
|
|
11
|
+
throw Error('Use <validation> inside <action>');
|
|
11
12
|
}
|
|
12
13
|
const { map, resource = 'body' } = props;
|
|
13
14
|
const run = () => {
|
|
@@ -5,7 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var innet = require('innet');
|
|
6
6
|
var utils = require('@cantinc/utils');
|
|
7
7
|
var jsx = require('@innet/jsx');
|
|
8
|
-
var
|
|
8
|
+
var useAction = require('../../hooks/useAction/useAction.js');
|
|
9
|
+
require('../../hooks/useServer/useServer.js');
|
|
9
10
|
|
|
10
11
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
12
|
|
|
@@ -14,9 +15,9 @@ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
|
14
15
|
var validationContext = new jsx.Context({});
|
|
15
16
|
function validation(_a, handler) {
|
|
16
17
|
var props = _a.props, children = _a.children;
|
|
17
|
-
var action = handler
|
|
18
|
+
var action = useAction.actionContext.get(handler);
|
|
18
19
|
if (!action) {
|
|
19
|
-
throw Error('
|
|
20
|
+
throw Error('Use <validation> inside <action>');
|
|
20
21
|
}
|
|
21
22
|
var map = props.map, _b = props.resource, resource = _b === void 0 ? 'body' : _b;
|
|
22
23
|
var run = function () {
|
|
@@ -3,7 +3,6 @@ import { CookieSerializeOptions } from 'cookie';
|
|
|
3
3
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
4
4
|
import { FormOptions } from 'multiparty';
|
|
5
5
|
import { ParsedQs } from 'qs';
|
|
6
|
-
export declare const ACTION: string;
|
|
7
6
|
export declare type Body = Record<string, any>;
|
|
8
7
|
export declare type Search = ParsedQs;
|
|
9
8
|
export declare type Cookies = Record<string, string | string[]>;
|
|
@@ -2,10 +2,8 @@ import { __decorate } from 'tslib';
|
|
|
2
2
|
import { once } from '@cantinc/utils';
|
|
3
3
|
import cookie from 'cookie';
|
|
4
4
|
import multiparty from 'multiparty';
|
|
5
|
-
import { parseSearch } from '../../
|
|
6
|
-
import 'qs';
|
|
5
|
+
import { parseSearch } from '../../parseSearch/parseSearch.es6.js';
|
|
7
6
|
|
|
8
|
-
const ACTION = Symbol('Action');
|
|
9
7
|
const URL_PARSER = /^(?<path>[^?]+)(\?(?<search>.*))?/;
|
|
10
8
|
const KEY_FIELD = /^(?<field>[^[]+)(?<rest>.*)$/;
|
|
11
9
|
const KEY_KEYS = /^\[(?<key>[^\]]+)\](?<rest>.*)$/;
|
|
@@ -133,4 +131,4 @@ __decorate([
|
|
|
133
131
|
once
|
|
134
132
|
], Action.prototype, "parsedUrl", null);
|
|
135
133
|
|
|
136
|
-
export {
|
|
134
|
+
export { Action, KEY_FIELD, KEY_KEYS, URL_PARSER };
|
|
@@ -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';
|