@innet/server 1.7.0 → 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 CHANGED
@@ -51,7 +51,9 @@ Try it out in `app.tsx`
51
51
  ```typescript jsx
52
52
  export default (
53
53
  <server>
54
- Hello World!
54
+ <action>
55
+ Hello World!
56
+ </action>
55
57
  </server>
56
58
  )
57
59
  ```
@@ -67,7 +69,9 @@ To change the port of the web server you can use `port` prop.
67
69
  ```typescript jsx
68
70
  export default (
69
71
  <server port={80}>
70
- Hello World!
72
+ <action>
73
+ Hello World!
74
+ </action>
71
75
  </server>
72
76
  )
73
77
  ```
@@ -85,7 +89,9 @@ const ssl = {
85
89
 
86
90
  export default (
87
91
  <server ssl={ssl}>
88
- Hello World!
92
+ <action>
93
+ Hello World!
94
+ </action>
89
95
  </server>
90
96
  )
91
97
  ```
@@ -97,7 +103,9 @@ You can show some message or do something right after the server starts.
97
103
  ```typescript jsx
98
104
  export default (
99
105
  <server onStart={console.log}>
100
- Hello World!
106
+ <action>
107
+ Hello World!
108
+ </action>
101
109
  </server>
102
110
  )
103
111
  ```
@@ -108,7 +116,9 @@ You can log errors or do something else, when the server get an error.
108
116
  ```typescript jsx
109
117
  export default (
110
118
  <server onError={console.error}>
111
- Hello World!
119
+ <action>
120
+ Hello World!
121
+ </action>
112
122
  </server>
113
123
  )
114
124
  ```
@@ -119,7 +129,9 @@ You can log any request with `onRequest` prop.
119
129
  ```typescript jsx
120
130
  export default (
121
131
  <server onRequest={console.log}>
122
- Hello World!
132
+ <action>
133
+ Hello World!
134
+ </action>
123
135
  </server>
124
136
  )
125
137
  ```
@@ -131,7 +143,9 @@ You can react on destroy the server with `onDestroy` prop.
131
143
  export default (
132
144
  <server
133
145
  onDestroy={() => console.log('destroy')}>
134
- Hello World!
146
+ <action>
147
+ Hello World!
148
+ </action>
135
149
  </server>
136
150
  )
137
151
  ```
@@ -142,14 +156,16 @@ You can use `html` element to return html content.
142
156
  ```typescript jsx
143
157
  export default (
144
158
  <server>
145
- <html>
146
- <head>
147
- <title>Innet App</title>
148
- </head>
149
- <body>
150
- Hello World!
151
- </body>
152
- </html>
159
+ <action>
160
+ <html>
161
+ <head>
162
+ <title>Innet App</title>
163
+ </head>
164
+ <body>
165
+ Hello World!
166
+ </body>
167
+ </html>
168
+ </action>
153
169
  </server>
154
170
  )
155
171
  ```
@@ -170,7 +186,9 @@ const content = (
170
186
 
171
187
  export default (
172
188
  <server>
173
- {content}
189
+ <action>
190
+ {content}
191
+ </action>
174
192
  </server>
175
193
  )
176
194
  ```
@@ -185,9 +203,11 @@ const content = (
185
203
 
186
204
  export default (
187
205
  <server>
188
- <header name='content-type' value='text/html'>
189
- {content}
190
- </header>
206
+ <action>
207
+ <header name='content-type' value='text/html'>
208
+ {content}
209
+ </header>
210
+ </action>
191
211
  </server>
192
212
  )
193
213
  ```
@@ -201,8 +221,10 @@ const content = (
201
221
 
202
222
  export default (
203
223
  <server>
204
- <header name='content-type' value='text/html' />
205
- {content}
224
+ <action>
225
+ <header name='content-type' value='text/html' />
226
+ {content}
227
+ </action>
206
228
  </server>
207
229
  )
208
230
  ```
@@ -213,9 +235,11 @@ You can return a file as a response.
213
235
  ```typescript jsx
214
236
  export default (
215
237
  <server>
216
- <header name='cache-control' value='max-age=300'>
217
- <file path='index.html' />
218
- </header>
238
+ <action>
239
+ <header name='cache-control' value='max-age=300'>
240
+ <file path='index.html' />
241
+ </header>
242
+ </action>
219
243
  </server>
220
244
  )
221
245
  ```
@@ -227,9 +251,11 @@ You can put content into the file to apply it only if the file does exist.
227
251
  ```typescript jsx
228
252
  export default (
229
253
  <server>
230
- <file path='index.html'>
231
- <header name='cache-control' value='max-age=300' />
232
- </file>
254
+ <action>
255
+ <file path='index.html'>
256
+ <header name='cache-control' value='max-age=300' />
257
+ </file>
258
+ </action>
233
259
  </server>
234
260
  )
235
261
  ```
@@ -241,9 +267,11 @@ The router helps to handle requests by route.
241
267
  ```typescript jsx
242
268
  export default (
243
269
  <server>
244
- <router>
245
- <file path='index.html' />
246
- </router>
270
+ <action>
271
+ <router>
272
+ <file path='index.html' />
273
+ </router>
274
+ </action>
247
275
  </server>
248
276
  )
249
277
  ```
@@ -257,9 +285,11 @@ This property says that the content of the route should be run if the request me
257
285
  ```typescript jsx
258
286
  export default (
259
287
  <server>
260
- <router method='GET'>
261
- <file path='index.html' />
262
- </router>
288
+ <action>
289
+ <router method='GET'>
290
+ <file path='index.html' />
291
+ </router>
292
+ </action>
263
293
  </server>
264
294
  )
265
295
  ```
@@ -270,9 +300,11 @@ You can set `path` to match with it.
270
300
  ```typescript jsx
271
301
  export default (
272
302
  <server>
273
- <router method='GET' path='/'>
274
- <file path='index.html' />
275
- </router>
303
+ <action>
304
+ <router method='GET' path='/'>
305
+ <file path='index.html' />
306
+ </router>
307
+ </action>
276
308
  </server>
277
309
  )
278
310
  ```
@@ -284,9 +316,11 @@ This prop has regex like syntax, so you can set the path as you wish.
284
316
  ```typescript jsx
285
317
  export default (
286
318
  <server>
287
- <router path='/user/[0-9]+'>
288
- <file path='index.html' />
289
- </router>
319
+ <action>
320
+ <router path='/user/[0-9]+'>
321
+ <file path='index.html' />
322
+ </router>
323
+ </action>
290
324
  </server>
291
325
  )
292
326
  ```
@@ -296,9 +330,11 @@ To provide named params from url, use named capturing groups of regex.
296
330
  ```typescript jsx
297
331
  export default (
298
332
  <server>
299
- <router path='/user/(?<id>[\w-]+)'>
300
- <file path='index.html' />
301
- </router>
333
+ <action>
334
+ <router path='/user/(?<id>[\w-]+)'>
335
+ <file path='index.html' />
336
+ </router>
337
+ </action>
302
338
  </server>
303
339
  )
304
340
  ```
@@ -309,9 +345,11 @@ You can react on any path which starts with provided one.
309
345
  ```typescript jsx
310
346
  export default (
311
347
  <server>
312
- <router path='/test' ish>
313
- <file path='index.html' />
314
- </router>
348
+ <action>
349
+ <router path='/test' ish>
350
+ <file path='index.html' />
351
+ </router>
352
+ </action>
315
353
  </server>
316
354
  )
317
355
  ```
@@ -326,14 +364,16 @@ You can use a router inside another one and `prefix` helps reduce path prop.
326
364
  ```typescript jsx
327
365
  export default (
328
366
  <server>
329
- <router path='/test' prefix='/test' ish>
330
- <router path='/'>
331
- <file path='index.html' />
367
+ <action>
368
+ <router path='/test' prefix='/test' ish>
369
+ <router path='/'>
370
+ <file path='index.html' />
371
+ </router>
372
+ <router path='/404'>
373
+ <file path='404.html' />
374
+ </router>
332
375
  </router>
333
- <router path='/404'>
334
- <file path='404.html' />
335
- </router>
336
- </router>
376
+ </action>
337
377
  </server>
338
378
  )
339
379
  ```
@@ -347,9 +387,11 @@ You can log the requests of any router.
347
387
  ```typescript jsx
348
388
  export default (
349
389
  <server>
350
- <router path='/test' onMatch={console.log}>
351
- <file path='index.html' />
352
- </router>
390
+ <action>
391
+ <router path='/test' onMatch={console.log}>
392
+ <file path='index.html' />
393
+ </router>
394
+ </action>
353
395
  </server>
354
396
  )
355
397
  ```
@@ -364,12 +406,14 @@ To avoid this you can use switch element.
364
406
  ```typescript jsx
365
407
  export default (
366
408
  <server>
367
- <switch>
368
- <router path='/'>
369
- <file path='index.html' />
370
- </router>
371
- <file path='404.html' />
372
- </switch>
409
+ <action>
410
+ <switch>
411
+ <router path='/'>
412
+ <file path='index.html' />
413
+ </router>
414
+ <file path='404.html' />
415
+ </switch>
416
+ </action>
373
417
  </server>
374
418
  )
375
419
  ```
@@ -384,10 +428,12 @@ CMS helps to return files from a folder by path.
384
428
  ```typescript jsx
385
429
  export default (
386
430
  <server>
387
- <switch>
388
- <cms dir='cms' />
389
- <file path='404.html' />
390
- </switch>
431
+ <action>
432
+ <switch>
433
+ <cms dir='cms' />
434
+ <file path='404.html' />
435
+ </switch>
436
+ </action>
391
437
  </server>
392
438
  )
393
439
  ```
@@ -399,12 +445,14 @@ You can use prefix with router to handle specific path.
399
445
  ```typescript jsx
400
446
  export default (
401
447
  <server>
402
- <switch>
403
- <router path='/cms' ish>
404
- <cms dir='cms' prefix='/cms' />
405
- </router>
406
- <file path='404.html' />
407
- </switch>
448
+ <action>
449
+ <switch>
450
+ <router path='/cms' ish>
451
+ <cms dir='cms' prefix='/cms' />
452
+ </router>
453
+ <file path='404.html' />
454
+ </switch>
455
+ </action>
408
456
  </server>
409
457
  )
410
458
  ```
@@ -414,12 +462,14 @@ You can input something into `cms`, if requested file is exist then the content
414
462
  ```typescript jsx
415
463
  export default (
416
464
  <server>
417
- <switch>
418
- <cms dir='cms'>
419
- <header name='cache-control' value='max-age=300' />
420
- </cms>
421
- <file path='404.html' />
422
- </switch>
465
+ <action>
466
+ <switch>
467
+ <cms dir='cms'>
468
+ <header name='cache-control' value='max-age=300' />
469
+ </cms>
470
+ <file path='404.html' />
471
+ </switch>
472
+ </action>
423
473
  </server>
424
474
  )
425
475
  ```
@@ -430,10 +480,12 @@ You can proxy request.
430
480
  ```typescript jsx
431
481
  export default (
432
482
  <server>
433
- <switch>
434
- <cms dir='cms' />
435
- <proxy to='https://site.com' />
436
- </switch>
483
+ <action>
484
+ <switch>
485
+ <cms dir='cms' />
486
+ <proxy to='https://site.com' />
487
+ </switch>
488
+ </action>
437
489
  </server>
438
490
  )
439
491
  ```
@@ -447,10 +499,12 @@ You can redirect users to another resource.
447
499
  ```typescript jsx
448
500
  export default (
449
501
  <server>
450
- <switch>
451
- <cms dir='cms' />
452
- <redirect to='https://site.com' />
453
- </switch>
502
+ <action>
503
+ <switch>
504
+ <cms dir='cms' />
505
+ <redirect to='https://site.com' />
506
+ </switch>
507
+ </action>
454
508
  </server>
455
509
  )
456
510
  ```
@@ -461,10 +515,12 @@ By default, status is `301`, you can change it with `status` prop.
461
515
  ```typescript jsx
462
516
  export default (
463
517
  <server>
464
- <switch>
465
- <cms dir='cms' />
466
- <redirect to='https://site.com' status={302} />
467
- </switch>
518
+ <action>
519
+ <switch>
520
+ <cms dir='cms' />
521
+ <redirect to='https://site.com' status={302} />
522
+ </switch>
523
+ </action>
468
524
  </server>
469
525
  )
470
526
  ```
@@ -474,10 +530,12 @@ Also, you can use string key of status.
474
530
  ```typescript jsx
475
531
  export default (
476
532
  <server>
477
- <switch>
478
- <cms dir='cms' />
479
- <redirect to='https://site.com' status='found'/>
480
- </switch>
533
+ <action>
534
+ <switch>
535
+ <cms dir='cms' />
536
+ <redirect to='https://site.com' status='found'/>
537
+ </switch>
538
+ </action>
481
539
  </server>
482
540
  )
483
541
  ```
@@ -490,12 +548,14 @@ Any component is just a function which returns content that should be run.
490
548
  ```typescript jsx
491
549
  export const Server = ({ cmsPrefix }) => (
492
550
  <server>
493
- <switch>
494
- <router path={cmsPrefix} ish>
495
- <cms dir='cms' prefix={cmsPrefix} />
496
- </router>
497
- <file path='404.html' />
498
- </switch>
551
+ <action>
552
+ <switch>
553
+ <router path={cmsPrefix} ish>
554
+ <cms dir='cms' prefix={cmsPrefix} />
555
+ </router>
556
+ <file path='404.html' />
557
+ </switch>
558
+ </action>
499
559
  </server>
500
560
  )
501
561
  ```
@@ -532,9 +592,11 @@ function Html ({ title }) {
532
592
 
533
593
  export default (
534
594
  <server>
535
- <Html title='main'>
536
- Hello World!
537
- </Html>
595
+ <action>
596
+ <Html title='main'>
597
+ Hello World!
598
+ </Html>
599
+ </action>
538
600
  </server>
539
601
  )
540
602
  ```
@@ -549,7 +611,9 @@ If you work on REST API, you can use `success` or `error` as an answer
549
611
  ```typescript jsx
550
612
  export default (
551
613
  <server>
552
- <success />
614
+ <action>
615
+ <success />
616
+ </action>
553
617
  </server>
554
618
  )
555
619
  ```
@@ -564,9 +628,11 @@ const data = {
564
628
 
565
629
  export default (
566
630
  <server>
567
- <success>
568
- {data}
569
- </success>
631
+ <action>
632
+ <success>
633
+ {data}
634
+ </success>
635
+ </action>
570
636
  </server>
571
637
  )
572
638
  ```
@@ -582,9 +648,11 @@ const data = {
582
648
 
583
649
  export default (
584
650
  <server>
585
- <success status='created'>
586
- {data}
587
- </success>
651
+ <action>
652
+ <success status='created'>
653
+ {data}
654
+ </success>
655
+ </action>
588
656
  </server>
589
657
  )
590
658
  ```
@@ -600,9 +668,11 @@ const data = {
600
668
 
601
669
  export default (
602
670
  <server>
603
- <success status={201}>
604
- {data}
605
- </success>
671
+ <action>
672
+ <success status={201}>
673
+ {data}
674
+ </success>
675
+ </action>
606
676
  </server>
607
677
  )
608
678
  ```
@@ -613,7 +683,9 @@ You can return an error to the user.
613
683
  ```typescript jsx
614
684
  export default (
615
685
  <server>
616
- <error />
686
+ <action>
687
+ <error />
688
+ </action>
617
689
  </server>
618
690
  )
619
691
  ```
@@ -629,9 +701,11 @@ const data = {
629
701
 
630
702
  export default (
631
703
  <server>
632
- <error>
633
- {data}
634
- </error>
704
+ <action>
705
+ <error>
706
+ {data}
707
+ </error>
708
+ </action>
635
709
  </server>
636
710
  )
637
711
  ```
@@ -646,9 +720,11 @@ const data = {
646
720
 
647
721
  export default (
648
722
  <server>
649
- <error status='notFound'>
650
- {data}
651
- </error>
723
+ <action>
724
+ <error status='notFound'>
725
+ {data}
726
+ </error>
727
+ </action>
652
728
  </server>
653
729
  )
654
730
  ```
@@ -661,9 +737,11 @@ const data = {
661
737
 
662
738
  export default (
663
739
  <server>
664
- <error status={404}>
665
- {data}
666
- </error>
740
+ <action>
741
+ <error status={404}>
742
+ {data}
743
+ </error>
744
+ </action>
667
745
  </server>
668
746
  )
669
747
  ```
@@ -680,7 +758,9 @@ const Login = ({ token }) => (
680
758
 
681
759
  export default (
682
760
  <server>
683
- <Login token='test' />
761
+ <action>
762
+ <Login token='test' />
763
+ </action>
684
764
  </server>
685
765
  )
686
766
  ```
@@ -690,9 +770,11 @@ To remove cookie just provide key without value.
690
770
  ```typescript jsx
691
771
  export default (
692
772
  <server>
693
- <cookie key='token'>
694
- <success />
695
- </cookie>
773
+ <action>
774
+ <cookie key='token'>
775
+ <success />
776
+ </cookie>
777
+ </action>
696
778
  </server>
697
779
  )
698
780
  ```
@@ -814,9 +896,11 @@ Use named capturing groups of regex in a route path prop to add the `params`.
814
896
  ```typescript jsx
815
897
  export default (
816
898
  <server>
817
- <router path='/user/(?<id>[\w-]+)'>
818
- <Router />
819
- </router>
899
+ <action>
900
+ <router path='/user/(?<id>[\w-]+)'>
901
+ <Router />
902
+ </router>
903
+ </action>
820
904
  </server>
821
905
  )
822
906
  ```
package/index.es6.js CHANGED
@@ -6,7 +6,7 @@ export { success, successStatuses } from './plugins/success/success.es6.js';
6
6
  export { error, errorStatuses } from './plugins/error/error.es6.js';
7
7
  export { cms } from './plugins/cms/cms.es6.js';
8
8
  export { file } from './plugins/file/file.es6.js';
9
- export { proxy } from './plugins/proxy/proxy.es6.js';
9
+ export { proxy, proxyServer } from './plugins/proxy/proxy.es6.js';
10
10
  export { redirect, redirectStatuses } from './plugins/redirect/redirect.es6.js';
11
11
  export { validation, validationContext } from './plugins/validation/validation.es6.js';
12
12
  export { formatter } from './plugins/formatter/formatter.es6.js';
package/index.js CHANGED
@@ -50,6 +50,7 @@ exports.errorStatuses = error.errorStatuses;
50
50
  exports.cms = cms.cms;
51
51
  exports.file = file.file;
52
52
  exports.proxy = proxy.proxy;
53
+ exports.proxyServer = proxy.proxyServer;
53
54
  exports.redirect = redirect.redirect;
54
55
  exports.redirectStatuses = redirect.redirectStatuses;
55
56
  exports.validation = validation.validation;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innet/server",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "Create server-side application with innet",
5
5
  "main": "index.js",
6
6
  "module": "index.es6.js",
@@ -5,7 +5,7 @@ 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';
package/plugins/index.js CHANGED
@@ -33,6 +33,7 @@ exports.errorStatuses = error.errorStatuses;
33
33
  exports.cms = cms.cms;
34
34
  exports.file = file.file;
35
35
  exports.proxy = proxy.proxy;
36
+ exports.proxyServer = proxy.proxyServer;
36
37
  exports.redirect = redirect.redirect;
37
38
  exports.redirectStatuses = redirect.redirectStatuses;
38
39
  exports.validation = validation.validation;
@@ -1 +1 @@
1
- export { proxy } from './proxy.es6.js';
1
+ export { proxy, proxyServer } from './proxy.es6.js';
@@ -7,3 +7,4 @@ var proxy = require('./proxy.js');
7
7
 
8
8
 
9
9
  exports.proxy = proxy.proxy;
10
+ exports.proxyServer = proxy.proxyServer;
@@ -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 function proxy({ props: { to, secure } }: {
6
- props: {
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;
@@ -15,4 +15,4 @@ function proxy({ props: { to, secure = false } }, handler) {
15
15
  return CONTINUE;
16
16
  }
17
17
 
18
- export { proxy };
18
+ export { proxy, proxyServer };
@@ -25,3 +25,4 @@ function proxy(_a, handler) {
25
25
  }
26
26
 
27
27
  exports.proxy = proxy;
28
+ exports.proxyServer = proxyServer;