@@ -19,28 +19,52 @@ It works with express.js framework to run Node.js server. Custom renderer we hav
19
19
20
20
``` js
21
21
import React from ' react' ;
22
- import { ReactXpress , App , Static , Router , Get , Post } from ' ../lib' ;
22
+ import { resolve } from ' path' ;
23
+ import { ReactXpress , App , Static , Router , Get , Post , Res } from ' ../lib' ;
23
24
24
- const HomePage = () => < h1> Welcome to home page< / h1> ;
25
- const AboutPage = () => < h1> About Company < / h1> ;
25
+ const HomePage = () => < h1> Home page< / h1> ;
26
+ const AboutPage = () => < h1> About Page < / h1> ;
26
27
27
28
const ExpressApp = () => (
28
- < App port= {8080 }>
29
+ < App port= {process . env . PORT || 8080 }>
29
30
< Static publicPath= " /public" / >
30
31
< Router path= " /" >
31
- < Get content= {< HomePage / > } / >
32
- < Get path= " *" content= " Not Found" status= {404 } / >
33
- < / Router>
34
- < Router path= " /company" >
35
- < Get path= " /about" content= {< AboutPage / > } / >
36
- < / Router>
37
- < Router path= " /api" >
38
- < Post path= " /status" content= {{ msg: ' It is okay, bro' }} / >
32
+ < Get render= {HomePage} / >
33
+ < Get path= " /about" render= {AboutPage} / >
34
+ < Router path= " /api" >
35
+ < Post
36
+ path= " /status"
37
+ json= {{ msg: ' It is okay, bro' }}
38
+ handler= {(req ) => console .log (req .originalUrl )}
39
+ / >
40
+ < / Router>
41
+ < Updates / >
42
+ < Get path= " *" text= " Not Found" status= {404 } / >
39
43
< / Router>
40
44
< / App>
41
45
);
42
46
47
+ // Updates! 🤩
48
+ const Updates = () => (
49
+ <>
50
+ < Get path= " /redirect" >
51
+ < Res .Redirect statusCode= {301 } path= " https://ru.reactjs.org" / >
52
+ < / Get>
53
+ < Post path= " /json" >
54
+ < Res .Status statusCode= {401 } / >
55
+ < Res .Content json= {{ msg: ' No Access' }} contentType= " application/json" / >
56
+ < / Post>
57
+ < Get path= " /send-file" >
58
+ < Res .SendFile path= {resolve (' public/code-example.png' )} onError= {console .log } / >
59
+ < / Get>
60
+ < Get path= " /render" >
61
+ < Res .Render component= {() => < h1> Shut Up And Take My Money! < / h1> } / >
62
+ < / Get>
63
+ < / >
64
+ );
65
+
43
66
ReactXpress .render (< ExpressApp / > );
67
+
44
68
```
45
69
46
70
### How to use
0 commit comments