@innet/server 1.1.1 → 1.3.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/README.md CHANGED
@@ -124,6 +124,18 @@ export default (
124
124
  )
125
125
  ```
126
126
 
127
+ ### onDestroy
128
+ You can react on destroy the server with `onDestroy` prop.
129
+
130
+ ```typescript jsx
131
+ export default (
132
+ <server
133
+ onDestroy={() => console.log('destroy')}>
134
+ Hello World!
135
+ </server>
136
+ )
137
+ ```
138
+
127
139
  ## HTML
128
140
  You can use `html` element to return html content.
129
141
 
@@ -455,9 +467,9 @@ export default (
455
467
  )
456
468
  ```
457
469
 
458
- ## Templates
470
+ ## Components
459
471
 
460
- Any template is just a function which returns content that should be run.
472
+ Any component is just a function which returns content that should be run.
461
473
 
462
474
  `server.tsx`
463
475
  ```typescript jsx
@@ -508,39 +520,7 @@ export default (
508
520
 
509
521
  The first argument is props, the second is children and the last one is a handler.
510
522
 
511
- You can use templates inside other templates and components.
512
-
513
- ## Components
514
- Component has the same functionality as template but this is a class.
515
-
516
- ```typescript jsx
517
- class Html {
518
- init ({ title }, children) {
519
- return (
520
- <header name='content-type' value='text/html'>
521
- <html>
522
- <head>
523
- <title>{title}</title>
524
- </head>
525
- <body>
526
- {children}
527
- </body>
528
- </html>
529
- </header>
530
- )
531
- }
532
- }
533
-
534
- export default (
535
- <server>
536
- <Html title='main'>
537
- Hello World!
538
- </Html>
539
- </server>
540
- )
541
- ```
542
-
543
- constructor of the class gets the same arguments as init method and the same as a template.
523
+ You can use components inside another component.
544
524
 
545
525
  ## success
546
526
  If you work on REST API, you can use `success` or `error` as an answer
@@ -696,19 +676,19 @@ export default (
696
676
  )
697
677
  ```
698
678
 
699
- ## ACTION
679
+ ## getAction
700
680
  Action is an object which contains `request` and `response`.
701
681
  Also, it contains a couple of fields and methods.
702
682
 
703
- Action available in templates and components.
683
+ Action available in components.
704
684
 
705
685
  ```typescript jsx
706
- import { ACTION } from '@innet/server'
686
+ import { getAction } from '@innet/server'
707
687
 
708
688
  const Test = (props, child, handler) => {
709
- const action = handler[ACTION]
689
+ const action = getAction(handler)
710
690
  const { req, res } = action
711
-
691
+
712
692
  console.log(req, res)
713
693
  }
714
694
  ```
@@ -717,10 +697,10 @@ const Test = (props, child, handler) => {
717
697
  You can get cookies as an object from an action.
718
698
 
719
699
  ```typescript jsx
720
- import { ACTION } from '@innet/server'
700
+ import { getAction } from '@innet/server'
721
701
 
722
702
  const Cookies = (props, child, handler) => {
723
- const { cookies } = handler[ACTION]
703
+ const { cookies } = getAction(handler)
724
704
 
725
705
  return <success>{cookies}</success>
726
706
  }
@@ -730,12 +710,11 @@ const Cookies = (props, child, handler) => {
730
710
  You can set cookie with action.
731
711
 
732
712
  ```typescript jsx
733
- import { ACTION } from '@innet/server'
713
+ import { getAction } from '@innet/server'
734
714
 
735
715
  const Login = (props, child, handler) => {
736
- const action = handler[ACTION]
737
-
738
- action.setCookie('user', 'token')
716
+ getAction(handler)
717
+ .setCookie('user', 'token')
739
718
  }
740
719
  ```
741
720
 
@@ -743,10 +722,10 @@ const Login = (props, child, handler) => {
743
722
  You can get current path with action.
744
723
 
745
724
  ```typescript jsx
746
- import { ACTION } from '@innet/server'
725
+ import { getAction } from '@innet/server'
747
726
 
748
727
  const Path = (props, child, handler) => {
749
- const { path } = handler[ACTION]
728
+ const { path } = getAction(handler)
750
729
 
751
730
  return path
752
731
  }
@@ -756,10 +735,10 @@ const Path = (props, child, handler) => {
756
735
  You can get current search as an object.
757
736
 
758
737
  ```typescript jsx
759
- import { ACTION } from '@innet/server'
738
+ import { getAction } from '@innet/server'
760
739
 
761
740
  const Search = (props, child, handler) => {
762
- const { search } = handler[ACTION]
741
+ const { search } = getAction(handler)
763
742
 
764
743
  return <success>{search}</success>
765
744
  }
@@ -769,10 +748,10 @@ const Search = (props, child, handler) => {
769
748
  You can parse body, and get values.
770
749
 
771
750
  ```typescript jsx
772
- import { ACTION } from '@innet/server'
751
+ import { getAction } from '@innet/server'
773
752
 
774
753
  const Body = async (props, child, handler) => {
775
- const action = handler[ACTION]
754
+ const action = getAction(handler)
776
755
 
777
756
  await action.parseBody()
778
757
 
@@ -784,10 +763,10 @@ const Body = async (props, child, handler) => {
784
763
  You can get files from a user.
785
764
 
786
765
  ```typescript jsx
787
- import { ACTION } from '@innet/server'
766
+ import { getAction } from '@innet/server'
788
767
 
789
768
  const Body = async (props, child, handler) => {
790
- const action = handler[ACTION]
769
+ const action = getAction(handler)
791
770
 
792
771
  await action.parseBody()
793
772
 
@@ -795,15 +774,15 @@ const Body = async (props, child, handler) => {
795
774
  }
796
775
  ```
797
776
 
798
- ## ROUTER
777
+ ## getRouter
799
778
 
800
- You can get router data in a template or component
779
+ You can get router data in a component
801
780
 
802
781
  ```typescript jsx
803
- import { ROUTER } from '@innet/server'
782
+ import { getRouter } from '@innet/server'
804
783
 
805
784
  const Router = async (props, child, handler) => {
806
- const { prefix, params } = handler[ROUTER]
785
+ const { prefix, params } = getRouter(handler)
807
786
 
808
787
  return <success>{{ prefix, params }}</success>
809
788
  }
@@ -0,0 +1,3 @@
1
+ import { Handler } from 'innet';
2
+ import { Action, ActionOptions } from '../Action';
3
+ export declare function getAction<O extends ActionOptions>(handler: Handler): Action<O>;
@@ -0,0 +1,7 @@
1
+ import { ACTION } from '../Action/Action.es6.js';
2
+
3
+ function getAction(handler) {
4
+ return handler[ACTION];
5
+ }
6
+
7
+ export { getAction };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var Action = require('../Action/Action.js');
6
+
7
+ function getAction(handler) {
8
+ return handler[Action.ACTION];
9
+ }
10
+
11
+ exports.getAction = getAction;
@@ -0,0 +1 @@
1
+ export * from './getAction';
@@ -0,0 +1 @@
1
+ export { getAction } from './getAction.es6.js';
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var getAction = require('./getAction.js');
6
+
7
+
8
+
9
+ exports.getAction = getAction.getAction;
package/action/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './Action';
2
2
  export * from './withAction';
3
+ export * from './getAction';
@@ -1,2 +1,3 @@
1
1
  export { ACTION, Action, URL_PARSER } from './Action/Action.es6.js';
2
2
  export { withAction } from './withAction/withAction.es6.js';
3
+ export { getAction } from './getAction/getAction.es6.js';
package/action/index.js CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var Action = require('./Action/Action.js');
6
6
  var withAction = require('./withAction/withAction.js');
7
+ var getAction = require('./getAction/getAction.js');
7
8
 
8
9
 
9
10
 
@@ -11,3 +12,4 @@ exports.ACTION = Action.ACTION;
11
12
  exports.Action = Action.Action;
12
13
  exports.URL_PARSER = Action.URL_PARSER;
13
14
  exports.withAction = withAction.withAction;
15
+ exports.getAction = getAction.getAction;
@@ -0,0 +1 @@
1
+ export * from './serverFn';
@@ -0,0 +1 @@
1
+ export { serverFn } from './serverFn.es6.js';
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var serverFn = require('./serverFn.js');
6
+
7
+
8
+
9
+ exports.serverFn = serverFn.serverFn;
@@ -0,0 +1,2 @@
1
+ import { PluginHandler } from 'innet';
2
+ export declare function serverFn(): PluginHandler;
@@ -0,0 +1,12 @@
1
+ import innet from 'innet';
2
+ import { Watch } from 'watch-state';
3
+
4
+ function serverFn() {
5
+ return (fn, next, handler) => {
6
+ let result;
7
+ new Watch(update => result = innet(fn(update), handler));
8
+ return result;
9
+ };
10
+ }
11
+
12
+ export { serverFn };
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var innet = require('innet');
6
+ var watchState = require('watch-state');
7
+
8
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
+
10
+ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
11
+
12
+ function serverFn() {
13
+ return function (fn, next, handler) {
14
+ var result;
15
+ new watchState.Watch(function (update) { return result = innet__default["default"](fn(update), handler); });
16
+ return result;
17
+ };
18
+ }
19
+
20
+ exports.serverFn = serverFn;
@@ -1,8 +1,9 @@
1
1
  import html from '@innet/html';
2
2
  import { switchAsync, SwitchProps } from '@innet/switch';
3
- import { arrayAsync } from '@innet/utils';
3
+ import { arrayAsync, async } from '@innet/utils';
4
4
  import { cms, CmsProps, cookie, CookieProps, error, ErrorProps, file, FileProps, header, HeaderProps, proxy, ProxyProps, router, RouterProps, success, SuccessProps, redirect, RedirectProps } from '../plugins';
5
5
  import { server, ServerProps } from '../server';
6
+ import { serverFn } from '../experimental/serverFn';
6
7
  export declare const arrayPlugins: (typeof arrayAsync)[];
7
8
  export declare const JSXPlugins: {
8
9
  server: typeof server;
@@ -18,7 +19,9 @@ export declare const JSXPlugins: {
18
19
  proxy: typeof proxy;
19
20
  redirect: typeof redirect;
20
21
  };
22
+ export declare const fnPlugins: (typeof serverFn)[];
21
23
  export declare const objectPlugins: ((handler: any) => import("innet").PluginHandler)[];
24
+ export declare const promisePlugins: (typeof async)[];
22
25
  declare const _default: import("innet").Handler;
23
26
  export default _default;
24
27
  declare global {
@@ -1,7 +1,7 @@
1
1
  import html from '@innet/html';
2
- import { jsxPlugins, jsxComponent, jsxTemplate } from '@innet/jsx';
2
+ import { jsxPlugins, jsxTemplate } from '@innet/jsx';
3
3
  import { switchAsync } from '@innet/switch';
4
- import { async, array, object, arrayAsync, arrayClear, arraySingleLess } from '@innet/utils';
4
+ import { promise, array, object, fn, arrayAsync, arrayClear, arraySingleLess, async } from '@innet/utils';
5
5
  import { createHandler } from 'innet';
6
6
  import { cookie } from '../plugins/cookie/cookie.es6.js';
7
7
  import { header } from '../plugins/header/header.es6.js';
@@ -13,6 +13,7 @@ import { file } from '../plugins/file/file.es6.js';
13
13
  import { proxy } from '../plugins/proxy/proxy.es6.js';
14
14
  import { redirect } from '../plugins/redirect/redirect.es6.js';
15
15
  import { server } from '../server/server.es6.js';
16
+ import { serverFn } from '../experimental/serverFn/serverFn.es6.js';
16
17
 
17
18
  const arrayPlugins = [
18
19
  arrayAsync,
@@ -33,15 +34,21 @@ const JSXPlugins = {
33
34
  proxy,
34
35
  redirect,
35
36
  };
37
+ const fnPlugins = [
38
+ serverFn,
39
+ ];
36
40
  const objectPlugins = [
37
41
  jsxPlugins(JSXPlugins),
38
- jsxComponent,
39
42
  jsxTemplate,
40
43
  ];
41
- var handler = createHandler([
44
+ const promisePlugins = [
42
45
  async,
46
+ ];
47
+ var handler = createHandler([
48
+ promise(promisePlugins),
43
49
  array(arrayPlugins),
44
50
  object(objectPlugins),
51
+ fn(fnPlugins),
45
52
  ]);
46
53
 
47
- export { JSXPlugins, arrayPlugins, handler as default, objectPlugins };
54
+ export { JSXPlugins, arrayPlugins, handler as default, fnPlugins, objectPlugins, promisePlugins };
@@ -17,6 +17,7 @@ var file = require('../plugins/file/file.js');
17
17
  var proxy = require('../plugins/proxy/proxy.js');
18
18
  var redirect = require('../plugins/redirect/redirect.js');
19
19
  var server = require('../server/server.js');
20
+ var serverFn = require('../experimental/serverFn/serverFn.js');
20
21
 
21
22
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
22
23
 
@@ -41,18 +42,26 @@ var JSXPlugins = {
41
42
  proxy: proxy.proxy,
42
43
  redirect: redirect.redirect,
43
44
  };
45
+ var fnPlugins = [
46
+ serverFn.serverFn,
47
+ ];
44
48
  var objectPlugins = [
45
49
  jsx.jsxPlugins(JSXPlugins),
46
- jsx.jsxComponent,
47
50
  jsx.jsxTemplate,
48
51
  ];
49
- var handler = innet.createHandler([
52
+ var promisePlugins = [
50
53
  utils.async,
54
+ ];
55
+ var handler = innet.createHandler([
56
+ utils.promise(promisePlugins),
51
57
  utils.array(arrayPlugins),
52
58
  utils.object(objectPlugins),
59
+ utils.fn(fnPlugins),
53
60
  ]);
54
61
 
55
62
  exports.JSXPlugins = JSXPlugins;
56
63
  exports.arrayPlugins = arrayPlugins;
57
64
  exports["default"] = handler;
65
+ exports.fnPlugins = fnPlugins;
58
66
  exports.objectPlugins = objectPlugins;
67
+ exports.promisePlugins = promisePlugins;
@@ -1 +1 @@
1
- export { JSXPlugins, arrayPlugins, default, objectPlugins } from './handler.es6.js';
1
+ export { JSXPlugins, arrayPlugins, default, fnPlugins, objectPlugins, promisePlugins } from './handler.es6.js';
package/handler/index.js CHANGED
@@ -9,4 +9,6 @@ var handler = require('./handler.js');
9
9
  exports.JSXPlugins = handler.JSXPlugins;
10
10
  exports.arrayPlugins = handler.arrayPlugins;
11
11
  exports["default"] = handler["default"];
12
+ exports.fnPlugins = handler.fnPlugins;
12
13
  exports.objectPlugins = handler.objectPlugins;
14
+ exports.promisePlugins = handler.promisePlugins;
package/index.es6.js CHANGED
@@ -1,8 +1,8 @@
1
- export { JSXPlugins, arrayPlugins, default, objectPlugins } from './handler/handler.es6.js';
1
+ export { JSXPlugins, arrayPlugins, default, fnPlugins, objectPlugins, promisePlugins } from './handler/handler.es6.js';
2
2
  export { server } from './server/server.es6.js';
3
3
  export { cookie } from './plugins/cookie/cookie.es6.js';
4
4
  export { header } from './plugins/header/header.es6.js';
5
- export { ROUTER, getMatchReg, router, withRouter } from './plugins/router/router.es6.js';
5
+ export { ROUTER, getMatchReg, getRouter, router, withRouter } from './plugins/router/router.es6.js';
6
6
  export { success, successStatuses } from './plugins/success/success.es6.js';
7
7
  export { error, errorStatuses } from './plugins/error/error.es6.js';
8
8
  export { cms } from './plugins/cms/cms.es6.js';
@@ -11,3 +11,4 @@ export { proxy } from './plugins/proxy/proxy.es6.js';
11
11
  export { redirect, redirectStatuses } from './plugins/redirect/redirect.es6.js';
12
12
  export { ACTION, Action, URL_PARSER } from './action/Action/Action.es6.js';
13
13
  export { withAction } from './action/withAction/withAction.es6.js';
14
+ export { getAction } from './action/getAction/getAction.es6.js';
package/index.js CHANGED
@@ -15,18 +15,22 @@ var proxy = require('./plugins/proxy/proxy.js');
15
15
  var redirect = require('./plugins/redirect/redirect.js');
16
16
  var Action = require('./action/Action/Action.js');
17
17
  var withAction = require('./action/withAction/withAction.js');
18
+ var getAction = require('./action/getAction/getAction.js');
18
19
 
19
20
 
20
21
 
21
22
  exports.JSXPlugins = handler.JSXPlugins;
22
23
  exports.arrayPlugins = handler.arrayPlugins;
23
24
  exports["default"] = handler["default"];
25
+ exports.fnPlugins = handler.fnPlugins;
24
26
  exports.objectPlugins = handler.objectPlugins;
27
+ exports.promisePlugins = handler.promisePlugins;
25
28
  exports.server = server.server;
26
29
  exports.cookie = cookie.cookie;
27
30
  exports.header = header.header;
28
31
  exports.ROUTER = router.ROUTER;
29
32
  exports.getMatchReg = router.getMatchReg;
33
+ exports.getRouter = router.getRouter;
30
34
  exports.router = router.router;
31
35
  exports.withRouter = router.withRouter;
32
36
  exports.success = success.success;
@@ -42,3 +46,4 @@ exports.ACTION = Action.ACTION;
42
46
  exports.Action = Action.Action;
43
47
  exports.URL_PARSER = Action.URL_PARSER;
44
48
  exports.withAction = withAction.withAction;
49
+ exports.getAction = getAction.getAction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innet/server",
3
- "version": "1.1.1",
3
+ "version": "1.3.0",
4
4
  "description": "Create server-side application with innet",
5
5
  "main": "index.js",
6
6
  "module": "index.es6.js",
@@ -24,9 +24,9 @@
24
24
  "dependencies": {
25
25
  "@cantinc/utils": "^1.0.0",
26
26
  "@innet/html": "^1.0.0",
27
- "@innet/jsx": "^0.1.0",
27
+ "@innet/jsx": "^0.1.1",
28
28
  "@innet/switch": "^1.0.0",
29
- "@innet/utils": "^1.0.0",
29
+ "@innet/utils": "^1.1.0",
30
30
  "@types/cookie": "^0.4.1",
31
31
  "cookie": "^0.4.2",
32
32
  "http-proxy": "^1.18.1",
@@ -34,6 +34,7 @@
34
34
  "is-invalid-path": "^1.0.2",
35
35
  "mime": "^3.0.0",
36
36
  "multiparty": "^4.2.3",
37
- "tslib": "^2.3.1"
37
+ "tslib": "^2.3.1",
38
+ "watch-state": "^3.4.3"
38
39
  }
39
40
  }
@@ -1,6 +1,6 @@
1
1
  export { cookie } from './cookie/cookie.es6.js';
2
2
  export { header } from './header/header.es6.js';
3
- export { ROUTER, getMatchReg, router, withRouter } from './router/router.es6.js';
3
+ export { ROUTER, getMatchReg, getRouter, router, withRouter } from './router/router.es6.js';
4
4
  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';
package/plugins/index.js CHANGED
@@ -18,6 +18,7 @@ exports.cookie = cookie.cookie;
18
18
  exports.header = header.header;
19
19
  exports.ROUTER = router.ROUTER;
20
20
  exports.getMatchReg = router.getMatchReg;
21
+ exports.getRouter = router.getRouter;
21
22
  exports.router = router.router;
22
23
  exports.withRouter = router.withRouter;
23
24
  exports.success = success.success;
@@ -1 +1 @@
1
- export { ROUTER, getMatchReg, router, withRouter } from './router.es6.js';
1
+ export { ROUTER, getMatchReg, getRouter, router, withRouter } from './router.es6.js';
@@ -8,5 +8,6 @@ var router = require('./router.js');
8
8
 
9
9
  exports.ROUTER = router.ROUTER;
10
10
  exports.getMatchReg = router.getMatchReg;
11
+ exports.getRouter = router.getRouter;
11
12
  exports.router = router.router;
12
13
  exports.withRouter = router.withRouter;
@@ -22,6 +22,7 @@ export interface RouterComponentConstructor {
22
22
  new (props?: Props, children?: Children, handler?: Handler): RouterComponent;
23
23
  [key: string]: any;
24
24
  }
25
+ export declare function getRouter(handler: Handler): Router;
25
26
  export declare function withRouter<T extends RouterComponentConstructor>(target: T): T;
26
27
  export declare function router({ props, children }: {
27
28
  props: any;
@@ -6,6 +6,9 @@ function getMatchReg(props) {
6
6
  return `^${path ? `${path}${ish ? '(/[^?]*)?' : ''}` : '[^?]*'}(\\?.*)?$`;
7
7
  }
8
8
  const ROUTER = Symbol('Parent Router');
9
+ function getRouter(handler) {
10
+ return handler[ROUTER];
11
+ }
9
12
  function withRouter(target) {
10
13
  const originInit = target.prototype.init;
11
14
  target.prototype.init = function init(...args) {
@@ -51,4 +54,4 @@ function router({ props, children }, handler) {
51
54
  return innet(children.length > 1 ? children : children[0], newHandler);
52
55
  }
53
56
 
54
- export { ROUTER, getMatchReg, router, withRouter };
57
+ export { ROUTER, getMatchReg, getRouter, router, withRouter };
@@ -14,6 +14,9 @@ function getMatchReg(props) {
14
14
  return "^".concat(path ? "".concat(path).concat(ish ? '(/[^?]*)?' : '') : '[^?]*', "(\\?.*)?$");
15
15
  }
16
16
  var ROUTER = Symbol('Parent Router');
17
+ function getRouter(handler) {
18
+ return handler[ROUTER];
19
+ }
17
20
  function withRouter(target) {
18
21
  var originInit = target.prototype.init;
19
22
  target.prototype.init = function init() {
@@ -66,5 +69,6 @@ function router(_a, handler) {
66
69
 
67
70
  exports.ROUTER = ROUTER;
68
71
  exports.getMatchReg = getMatchReg;
72
+ exports.getRouter = getRouter;
69
73
  exports.router = router;
70
74
  exports.withRouter = withRouter;
@@ -11,6 +11,7 @@ export interface ServerProps {
11
11
  onStart?: (url: string) => any;
12
12
  onRequest?: (action: Action) => any;
13
13
  onError?: (e: Error) => any;
14
+ onDestroy?: () => any;
14
15
  }
15
16
  export declare function server({ props, children }: {
16
17
  props?: ServerProps;
@@ -3,6 +3,7 @@ import fs from 'fs';
3
3
  import http from 'http';
4
4
  import http2 from 'https';
5
5
  import innet from 'innet';
6
+ import { onDestroy } from 'watch-state';
6
7
  import { ACTION, Action } from '../action/Action/Action.es6.js';
7
8
  import { CONTINUE } from '../constants.es6.js';
8
9
 
@@ -19,6 +20,11 @@ function server({ props = {}, children }, handler) {
19
20
  const https = (key && cert);
20
21
  const { port = env.PORT || (https ? 442 : 80), unknownError = '', onStart, onError, onRequest } = props;
21
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
+ });
22
28
  server.on('request', (req, res) => __awaiter(this, void 0, void 0, function* () {
23
29
  const childHandler = Object.create(handler);
24
30
  childHandler[ACTION] = new Action(req, res);
package/server/server.js CHANGED
@@ -7,6 +7,7 @@ var fs = require('fs');
7
7
  var http = require('http');
8
8
  var http2 = require('https');
9
9
  var innet = require('innet');
10
+ var watchState = require('watch-state');
10
11
  var Action = require('../action/Action/Action.js');
11
12
  var constants = require('../constants.js');
12
13
 
@@ -32,6 +33,11 @@ function server(_a, handler) {
32
33
  var https = (key && cert);
33
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;
34
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
+ });
35
41
  server.on('request', function (req, res) { return tslib.__awaiter(_this, void 0, void 0, function () {
36
42
  var childHandler, result, e_1;
37
43
  return tslib.__generator(this, function (_a) {