@innet/server 1.0.4 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +61 -21
  2. package/action/Action/Action.d.ts +1 -1
  3. package/action/Action/Action.es6.js +1 -1
  4. package/action/Action/Action.js +1 -1
  5. package/action/Action/index.d.ts +0 -1
  6. package/action/Action/index.es6.js +1 -1
  7. package/action/Action/index.js +1 -1
  8. package/action/getAction/getAction.d.ts +3 -0
  9. package/action/getAction/getAction.es6.js +7 -0
  10. package/action/getAction/getAction.js +11 -0
  11. package/action/getAction/index.d.ts +1 -0
  12. package/action/getAction/index.es6.js +1 -0
  13. package/action/getAction/index.js +9 -0
  14. package/action/index.d.ts +1 -2
  15. package/action/index.es6.js +3 -2
  16. package/action/index.js +4 -2
  17. package/action/withAction/index.d.ts +0 -1
  18. package/action/withAction/index.es6.js +1 -1
  19. package/action/withAction/index.js +3 -1
  20. package/action/withAction/withAction.d.ts +2 -2
  21. package/action/withAction/withAction.es6.js +1 -1
  22. package/action/withAction/withAction.js +3 -1
  23. package/handler/handler.d.ts +3 -1
  24. package/handler/handler.es6.js +2 -0
  25. package/handler/handler.js +2 -0
  26. package/index.d.ts +0 -1
  27. package/index.es6.js +5 -3
  28. package/index.js +8 -2
  29. package/package.json +1 -1
  30. package/plugins/file/file.es6.js +0 -1
  31. package/plugins/file/file.js +0 -1
  32. package/plugins/index.d.ts +1 -0
  33. package/plugins/index.es6.js +2 -1
  34. package/plugins/index.js +4 -0
  35. package/plugins/redirect/index.d.ts +1 -0
  36. package/plugins/redirect/index.es6.js +1 -0
  37. package/plugins/redirect/index.js +10 -0
  38. package/plugins/redirect/redirect.d.ts +18 -0
  39. package/plugins/redirect/redirect.es6.js +27 -0
  40. package/plugins/redirect/redirect.js +33 -0
  41. package/plugins/router/index.es6.js +1 -1
  42. package/plugins/router/index.js +1 -0
  43. package/plugins/router/router.d.ts +2 -1
  44. package/plugins/router/router.es6.js +4 -1
  45. package/plugins/router/router.js +4 -0
  46. package/server/index.d.ts +0 -1
  47. package/server/index.es6.js +1 -1
  48. package/server/index.js +0 -1
  49. package/server/server.d.ts +1 -2
  50. package/server/server.es6.js +2 -2
  51. package/server/server.js +1 -2
package/README.md CHANGED
@@ -414,6 +414,47 @@ export default (
414
414
  In this case, if you have a file in cms folder then the file will return
415
415
  else makes request to the `site.com`.
416
416
 
417
+ ## redirect
418
+ You can redirect users to another resource.
419
+
420
+ ```typescript jsx
421
+ export default (
422
+ <server>
423
+ <switch>
424
+ <cms dir='cms' />
425
+ <redirect to='https://site.com' />
426
+ </switch>
427
+ </server>
428
+ )
429
+ ```
430
+
431
+ ### status
432
+ By default, status is `301`, you can change it with `status` prop.
433
+
434
+ ```typescript jsx
435
+ export default (
436
+ <server>
437
+ <switch>
438
+ <cms dir='cms' />
439
+ <redirect to='https://site.com' status={302} />
440
+ </switch>
441
+ </server>
442
+ )
443
+ ```
444
+
445
+ Also, you can use string key of status.
446
+
447
+ ```typescript jsx
448
+ export default (
449
+ <server>
450
+ <switch>
451
+ <cms dir='cms' />
452
+ <redirect to='https://site.com' status='found'/>
453
+ </switch>
454
+ </server>
455
+ )
456
+ ```
457
+
417
458
  ## Templates
418
459
 
419
460
  Any template is just a function which returns content that should be run.
@@ -655,19 +696,19 @@ export default (
655
696
  )
656
697
  ```
657
698
 
658
- ## ACTION
699
+ ## getAction
659
700
  Action is an object which contains `request` and `response`.
660
701
  Also, it contains a couple of fields and methods.
661
702
 
662
703
  Action available in templates and components.
663
704
 
664
705
  ```typescript jsx
665
- import { ACTION } from '@innet/server'
706
+ import { getAction } from '@innet/server'
666
707
 
667
708
  const Test = (props, child, handler) => {
668
- const action = handler[ACTION]
709
+ const action = getAction(handler)
669
710
  const { req, res } = action
670
-
711
+
671
712
  console.log(req, res)
672
713
  }
673
714
  ```
@@ -676,10 +717,10 @@ const Test = (props, child, handler) => {
676
717
  You can get cookies as an object from an action.
677
718
 
678
719
  ```typescript jsx
679
- import { ACTION } from '@innet/server'
720
+ import { getAction } from '@innet/server'
680
721
 
681
722
  const Cookies = (props, child, handler) => {
682
- const { cookies } = handler[ACTION]
723
+ const { cookies } = getAction(handler)
683
724
 
684
725
  return <success>{cookies}</success>
685
726
  }
@@ -689,12 +730,11 @@ const Cookies = (props, child, handler) => {
689
730
  You can set cookie with action.
690
731
 
691
732
  ```typescript jsx
692
- import { ACTION } from '@innet/server'
733
+ import { getAction } from '@innet/server'
693
734
 
694
735
  const Login = (props, child, handler) => {
695
- const action = handler[ACTION]
696
-
697
- action.setCookie('user', 'token')
736
+ getAction(handler)
737
+ .setCookie('user', 'token')
698
738
  }
699
739
  ```
700
740
 
@@ -702,10 +742,10 @@ const Login = (props, child, handler) => {
702
742
  You can get current path with action.
703
743
 
704
744
  ```typescript jsx
705
- import { ACTION } from '@innet/server'
745
+ import { getAction } from '@innet/server'
706
746
 
707
747
  const Path = (props, child, handler) => {
708
- const { path } = handler[ACTION]
748
+ const { path } = getAction(handler)
709
749
 
710
750
  return path
711
751
  }
@@ -715,10 +755,10 @@ const Path = (props, child, handler) => {
715
755
  You can get current search as an object.
716
756
 
717
757
  ```typescript jsx
718
- import { ACTION } from '@innet/server'
758
+ import { getAction } from '@innet/server'
719
759
 
720
760
  const Search = (props, child, handler) => {
721
- const { search } = handler[ACTION]
761
+ const { search } = getAction(handler)
722
762
 
723
763
  return <success>{search}</success>
724
764
  }
@@ -728,10 +768,10 @@ const Search = (props, child, handler) => {
728
768
  You can parse body, and get values.
729
769
 
730
770
  ```typescript jsx
731
- import { ACTION } from '@innet/server'
771
+ import { getAction } from '@innet/server'
732
772
 
733
773
  const Body = async (props, child, handler) => {
734
- const action = handler[ACTION]
774
+ const action = getAction(handler)
735
775
 
736
776
  await action.parseBody()
737
777
 
@@ -743,10 +783,10 @@ const Body = async (props, child, handler) => {
743
783
  You can get files from a user.
744
784
 
745
785
  ```typescript jsx
746
- import { ACTION } from '@innet/server'
786
+ import { getAction } from '@innet/server'
747
787
 
748
788
  const Body = async (props, child, handler) => {
749
- const action = handler[ACTION]
789
+ const action = getAction(handler)
750
790
 
751
791
  await action.parseBody()
752
792
 
@@ -754,15 +794,15 @@ const Body = async (props, child, handler) => {
754
794
  }
755
795
  ```
756
796
 
757
- ## ROUTER
797
+ ## getRouter
758
798
 
759
799
  You can get router data in a template or component
760
800
 
761
801
  ```typescript jsx
762
- import { ROUTER } from '@innet/server'
802
+ import { getRouter } from '@innet/server'
763
803
 
764
804
  const Router = async (props, child, handler) => {
765
- const { prefix, params } = handler[ROUTER]
805
+ const { prefix, params } = getRouter(handler)
766
806
 
767
807
  return <success>{{ prefix, params }}</success>
768
808
  }
@@ -23,7 +23,7 @@ export interface File {
23
23
  size: number;
24
24
  }
25
25
  export declare const URL_PARSER: RegExp;
26
- export default class Action<O extends ActionOptions = ActionOptions> {
26
+ export declare class Action<O extends ActionOptions = ActionOptions> {
27
27
  readonly req: Request;
28
28
  readonly res: Response;
29
29
  constructor(req: Request, res: Response);
@@ -94,4 +94,4 @@ __decorate([
94
94
  once
95
95
  ], Action.prototype, "parsedUrl", null);
96
96
 
97
- export { ACTION, URL_PARSER, Action as default };
97
+ export { ACTION, Action, URL_PARSER };
@@ -133,5 +133,5 @@ var Action = /** @class */ (function () {
133
133
  }());
134
134
 
135
135
  exports.ACTION = ACTION;
136
+ exports.Action = Action;
136
137
  exports.URL_PARSER = URL_PARSER;
137
- exports["default"] = Action;
@@ -1,2 +1 @@
1
- export { default } from './Action';
2
1
  export * from './Action';
@@ -1 +1 @@
1
- export { ACTION, URL_PARSER, default } from './Action.es6.js';
1
+ export { ACTION, Action, URL_PARSER } from './Action.es6.js';
@@ -7,5 +7,5 @@ var Action = require('./Action.js');
7
7
 
8
8
 
9
9
  exports.ACTION = Action.ACTION;
10
+ exports.Action = Action.Action;
10
11
  exports.URL_PARSER = Action.URL_PARSER;
11
- exports["default"] = Action["default"];
@@ -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,4 +1,3 @@
1
- export { default } from './Action';
2
1
  export * from './Action';
3
- export { default as withAction } from './withAction';
4
2
  export * from './withAction';
3
+ export * from './getAction';
@@ -1,2 +1,3 @@
1
- export { ACTION, URL_PARSER, default } from './Action/Action.es6.js';
2
- export { default as withAction } from './withAction/withAction.es6.js';
1
+ export { ACTION, Action, URL_PARSER } from './Action/Action.es6.js';
2
+ export { withAction } from './withAction/withAction.es6.js';
3
+ export { getAction } from './getAction/getAction.es6.js';
package/action/index.js CHANGED
@@ -4,10 +4,12 @@ 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
 
10
11
  exports.ACTION = Action.ACTION;
12
+ exports.Action = Action.Action;
11
13
  exports.URL_PARSER = Action.URL_PARSER;
12
- exports["default"] = Action["default"];
13
- exports.withAction = withAction;
14
+ exports.withAction = withAction.withAction;
15
+ exports.getAction = getAction.getAction;
@@ -1,2 +1 @@
1
- export { default } from './withAction';
2
1
  export * from './withAction';
@@ -1 +1 @@
1
- export { default } from './withAction.es6.js';
1
+ export { withAction } from './withAction.es6.js';
@@ -1,7 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  var withAction = require('./withAction.js');
4
6
 
5
7
 
6
8
 
7
- module.exports = withAction;
9
+ exports.withAction = withAction.withAction;
@@ -1,6 +1,6 @@
1
1
  import { Children, Component, Props } from '@innet/jsx';
2
2
  import { Handler } from 'innet';
3
- import Action, { Body } from '../Action';
3
+ import { Action, Body } from '../Action';
4
4
  export interface ActionComponent<B extends Body> extends Component {
5
5
  action: Action<B>;
6
6
  }
@@ -8,4 +8,4 @@ export interface RequestComponentConstructor<B extends Body> {
8
8
  new (props?: Props, children?: Children, handler?: Handler): ActionComponent<B>;
9
9
  [key: string]: any;
10
10
  }
11
- export default function withAction<B extends Body, T extends RequestComponentConstructor<B>>(target: T): T;
11
+ export declare function withAction<B extends Body, T extends RequestComponentConstructor<B>>(target: T): T;
@@ -9,4 +9,4 @@ function withAction(target) {
9
9
  return target;
10
10
  }
11
11
 
12
- export { withAction as default };
12
+ export { withAction };
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  var Action = require('../Action/Action.js');
4
6
 
5
7
  function withAction(target) {
@@ -15,4 +17,4 @@ function withAction(target) {
15
17
  return target;
16
18
  }
17
19
 
18
- module.exports = withAction;
20
+ exports.withAction = withAction;
@@ -1,7 +1,7 @@
1
1
  import html from '@innet/html';
2
2
  import { switchAsync, SwitchProps } from '@innet/switch';
3
3
  import { arrayAsync } from '@innet/utils';
4
- import { cms, CmsProps, cookie, CookieProps, error, ErrorProps, file, FileProps, header, HeaderProps, proxy, ProxyProps, router, RouterProps, success, SuccessProps } from '../plugins';
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
6
  export declare const arrayPlugins: (typeof arrayAsync)[];
7
7
  export declare const JSXPlugins: {
@@ -16,6 +16,7 @@ export declare const JSXPlugins: {
16
16
  cms: typeof cms;
17
17
  file: typeof file;
18
18
  proxy: typeof proxy;
19
+ redirect: typeof redirect;
19
20
  };
20
21
  export declare const objectPlugins: ((handler: any) => import("innet").PluginHandler)[];
21
22
  declare const _default: import("innet").Handler;
@@ -25,6 +26,7 @@ declare global {
25
26
  interface IntrinsicElements {
26
27
  server: ServerProps;
27
28
  router: RouterProps;
29
+ redirect: RedirectProps;
28
30
  cookie: CookieProps;
29
31
  success: SuccessProps;
30
32
  error: ErrorProps;
@@ -11,6 +11,7 @@ import { error } from '../plugins/error/error.es6.js';
11
11
  import { cms } from '../plugins/cms/cms.es6.js';
12
12
  import { file } from '../plugins/file/file.es6.js';
13
13
  import { proxy } from '../plugins/proxy/proxy.es6.js';
14
+ import { redirect } from '../plugins/redirect/redirect.es6.js';
14
15
  import { server } from '../server/server.es6.js';
15
16
 
16
17
  const arrayPlugins = [
@@ -30,6 +31,7 @@ const JSXPlugins = {
30
31
  cms,
31
32
  file,
32
33
  proxy,
34
+ redirect,
33
35
  };
34
36
  const objectPlugins = [
35
37
  jsxPlugins(JSXPlugins),
@@ -15,6 +15,7 @@ var error = require('../plugins/error/error.js');
15
15
  var cms = require('../plugins/cms/cms.js');
16
16
  var file = require('../plugins/file/file.js');
17
17
  var proxy = require('../plugins/proxy/proxy.js');
18
+ var redirect = require('../plugins/redirect/redirect.js');
18
19
  var server = require('../server/server.js');
19
20
 
20
21
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -38,6 +39,7 @@ var JSXPlugins = {
38
39
  cms: cms.cms,
39
40
  file: file.file,
40
41
  proxy: proxy.proxy,
42
+ redirect: redirect.redirect,
41
43
  };
42
44
  var objectPlugins = [
43
45
  jsx.jsxPlugins(JSXPlugins),
package/index.d.ts CHANGED
@@ -2,5 +2,4 @@ export { default } from './handler';
2
2
  export * from './server';
3
3
  export * from './plugins';
4
4
  export * from './handler';
5
- export { default as Action } from './action';
6
5
  export * from './action';
package/index.es6.js CHANGED
@@ -2,11 +2,13 @@ export { JSXPlugins, arrayPlugins, default, objectPlugins } from './handler/hand
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';
9
9
  export { file } from './plugins/file/file.es6.js';
10
10
  export { proxy } from './plugins/proxy/proxy.es6.js';
11
- export { ACTION, default as Action, URL_PARSER } from './action/Action/Action.es6.js';
12
- export { default as withAction } from './action/withAction/withAction.es6.js';
11
+ export { redirect, redirectStatuses } from './plugins/redirect/redirect.es6.js';
12
+ export { ACTION, Action, URL_PARSER } from './action/Action/Action.es6.js';
13
+ export { withAction } from './action/withAction/withAction.es6.js';
14
+ export { getAction } from './action/getAction/getAction.es6.js';
package/index.js CHANGED
@@ -12,8 +12,10 @@ var error = require('./plugins/error/error.js');
12
12
  var cms = require('./plugins/cms/cms.js');
13
13
  var file = require('./plugins/file/file.js');
14
14
  var proxy = require('./plugins/proxy/proxy.js');
15
+ var redirect = require('./plugins/redirect/redirect.js');
15
16
  var Action = require('./action/Action/Action.js');
16
17
  var withAction = require('./action/withAction/withAction.js');
18
+ var getAction = require('./action/getAction/getAction.js');
17
19
 
18
20
 
19
21
 
@@ -26,6 +28,7 @@ exports.cookie = cookie.cookie;
26
28
  exports.header = header.header;
27
29
  exports.ROUTER = router.ROUTER;
28
30
  exports.getMatchReg = router.getMatchReg;
31
+ exports.getRouter = router.getRouter;
29
32
  exports.router = router.router;
30
33
  exports.withRouter = router.withRouter;
31
34
  exports.success = success.success;
@@ -35,7 +38,10 @@ exports.errorStatuses = error.errorStatuses;
35
38
  exports.cms = cms.cms;
36
39
  exports.file = file.file;
37
40
  exports.proxy = proxy.proxy;
41
+ exports.redirect = redirect.redirect;
42
+ exports.redirectStatuses = redirect.redirectStatuses;
38
43
  exports.ACTION = Action.ACTION;
39
- exports.Action = Action["default"];
44
+ exports.Action = Action.Action;
40
45
  exports.URL_PARSER = Action.URL_PARSER;
41
- exports.withAction = withAction;
46
+ exports.withAction = withAction.withAction;
47
+ exports.getAction = getAction.getAction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innet/server",
3
- "version": "1.0.4",
3
+ "version": "1.1.2",
4
4
  "description": "Create server-side application with innet",
5
5
  "main": "index.js",
6
6
  "module": "index.es6.js",
@@ -20,7 +20,6 @@ function file({ props, children = null }, handler) {
20
20
  });
21
21
  }
22
22
  }
23
- res.statusCode = 404;
24
23
  }
25
24
 
26
25
  export { file };
@@ -30,7 +30,6 @@ function file(_a, handler) {
30
30
  });
31
31
  }
32
32
  }
33
- res.statusCode = 404;
34
33
  }
35
34
 
36
35
  exports.file = file;
@@ -6,3 +6,4 @@ export * from './error';
6
6
  export * from './cms';
7
7
  export * from './file';
8
8
  export * from './proxy';
9
+ export * from './redirect';
@@ -1,8 +1,9 @@
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';
7
7
  export { file } from './file/file.es6.js';
8
8
  export { proxy } from './proxy/proxy.es6.js';
9
+ export { redirect, redirectStatuses } from './redirect/redirect.es6.js';
package/plugins/index.js CHANGED
@@ -10,6 +10,7 @@ var error = require('./error/error.js');
10
10
  var cms = require('./cms/cms.js');
11
11
  var file = require('./file/file.js');
12
12
  var proxy = require('./proxy/proxy.js');
13
+ var redirect = require('./redirect/redirect.js');
13
14
 
14
15
 
15
16
 
@@ -17,6 +18,7 @@ exports.cookie = cookie.cookie;
17
18
  exports.header = header.header;
18
19
  exports.ROUTER = router.ROUTER;
19
20
  exports.getMatchReg = router.getMatchReg;
21
+ exports.getRouter = router.getRouter;
20
22
  exports.router = router.router;
21
23
  exports.withRouter = router.withRouter;
22
24
  exports.success = success.success;
@@ -26,3 +28,5 @@ exports.errorStatuses = error.errorStatuses;
26
28
  exports.cms = cms.cms;
27
29
  exports.file = file.file;
28
30
  exports.proxy = proxy.proxy;
31
+ exports.redirect = redirect.redirect;
32
+ exports.redirectStatuses = redirect.redirectStatuses;
@@ -0,0 +1 @@
1
+ export * from './redirect';
@@ -0,0 +1 @@
1
+ export { redirect, redirectStatuses } from './redirect.es6.js';
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var redirect = require('./redirect.js');
6
+
7
+
8
+
9
+ exports.redirect = redirect.redirect;
10
+ exports.redirectStatuses = redirect.redirectStatuses;
@@ -0,0 +1,18 @@
1
+ export interface RedirectProps {
2
+ to: string;
3
+ status?: number | keyof typeof redirectStatuses;
4
+ }
5
+ export declare const redirectStatuses: {
6
+ multipleChoices: number;
7
+ movedPermanently: number;
8
+ found: number;
9
+ seeOther: number;
10
+ notModified: number;
11
+ useProxy: number;
12
+ temporaryRedirect: number;
13
+ permanentRedirect: number;
14
+ };
15
+ export declare function redirect({ props, children }: {
16
+ props: any;
17
+ children: any;
18
+ }, handler: any): any;
@@ -0,0 +1,27 @@
1
+ import { ACTION } from '../../action/Action/Action.es6.js';
2
+
3
+ const redirectStatuses = {
4
+ multipleChoices: 300,
5
+ movedPermanently: 301,
6
+ found: 302,
7
+ seeOther: 303,
8
+ notModified: 304,
9
+ useProxy: 305,
10
+ temporaryRedirect: 307,
11
+ permanentRedirect: 308,
12
+ };
13
+ function getStatus(status) {
14
+ if (typeof status === 'number')
15
+ return status;
16
+ return redirectStatuses[status] || 301;
17
+ }
18
+ function redirect({ props, children }, handler) {
19
+ const { res } = handler[ACTION];
20
+ const { to, status = 301 } = props;
21
+ res.writeHead(getStatus(status), {
22
+ location: to,
23
+ });
24
+ return null;
25
+ }
26
+
27
+ export { redirect, redirectStatuses };
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var Action = require('../../action/Action/Action.js');
6
+
7
+ var redirectStatuses = {
8
+ multipleChoices: 300,
9
+ movedPermanently: 301,
10
+ found: 302,
11
+ seeOther: 303,
12
+ notModified: 304,
13
+ useProxy: 305,
14
+ temporaryRedirect: 307,
15
+ permanentRedirect: 308,
16
+ };
17
+ function getStatus(status) {
18
+ if (typeof status === 'number')
19
+ return status;
20
+ return redirectStatuses[status] || 301;
21
+ }
22
+ function redirect(_a, handler) {
23
+ var props = _a.props; _a.children;
24
+ var res = handler[Action.ACTION].res;
25
+ var to = props.to, _b = props.status, status = _b === void 0 ? 301 : _b;
26
+ res.writeHead(getStatus(status), {
27
+ location: to,
28
+ });
29
+ return null;
30
+ }
31
+
32
+ exports.redirect = redirect;
33
+ exports.redirectStatuses = redirectStatuses;
@@ -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;
@@ -1,6 +1,6 @@
1
1
  import { Children, Component, Props } from '@innet/jsx';
2
2
  import { Handler } from 'innet';
3
- import Action from '../../action';
3
+ import { Action } from '../../action';
4
4
  export declare type Methods = 'GET' | 'HEAD' | 'POST' | 'DELETE' | 'PUT' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
5
5
  export interface RouterProps {
6
6
  method?: Methods;
@@ -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;
package/server/index.d.ts CHANGED
@@ -1,2 +1 @@
1
- export { default } from './server';
2
1
  export * from './server';
@@ -1 +1 @@
1
- export { server as default, server } from './server.es6.js';
1
+ export { server } from './server.es6.js';
package/server/index.js CHANGED
@@ -6,5 +6,4 @@ var server = require('./server.js');
6
6
 
7
7
 
8
8
 
9
- exports["default"] = server.server;
10
9
  exports.server = server.server;
@@ -1,5 +1,5 @@
1
1
  import { Handler } from 'innet';
2
- import Action from '../action';
2
+ import { Action } from '../action';
3
3
  export interface SSL {
4
4
  cert: string;
5
5
  key: string;
@@ -16,4 +16,3 @@ export declare function server({ props, children }: {
16
16
  props?: ServerProps;
17
17
  children: any;
18
18
  }, handler: Handler): Promise<unknown>;
19
- export default server;
@@ -3,7 +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 Action, { ACTION } from '../action/Action/Action.es6.js';
6
+ import { ACTION, Action } from '../action/Action/Action.es6.js';
7
7
  import { CONTINUE } from '../constants.es6.js';
8
8
 
9
9
  const isInvalidPath = require('is-invalid-path');
@@ -60,4 +60,4 @@ function server({ props = {}, children }, handler) {
60
60
  return promise;
61
61
  }
62
62
 
63
- export { server as default, server };
63
+ export { server };
package/server/server.js CHANGED
@@ -38,7 +38,7 @@ function server(_a, handler) {
38
38
  switch (_a.label) {
39
39
  case 0:
40
40
  childHandler = Object.create(handler);
41
- childHandler[Action.ACTION] = new Action["default"](req, res);
41
+ childHandler[Action.ACTION] = new Action.Action(req, res);
42
42
  if (!onRequest) return [3 /*break*/, 2];
43
43
  return [4 /*yield*/, onRequest(childHandler[Action.ACTION])];
44
44
  case 1:
@@ -88,5 +88,4 @@ function server(_a, handler) {
88
88
  return promise;
89
89
  }
90
90
 
91
- exports["default"] = server;
92
91
  exports.server = server;