@@ -19,28 +19,52 @@ It works with express.js framework to run Node.js server. Custom renderer we hav
1919
2020``` js
2121import 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' ;
2324
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> ;
2627
2728const ExpressApp = () => (
28- < App port= {8080 }>
29+ < App port= {process . env . PORT || 8080 }>
2930 < Static publicPath= " /public" / >
3031 < 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 } / >
3943 < / Router>
4044 < / App>
4145);
4246
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+
4366ReactXpress .render (< ExpressApp / > );
67+
4468```
4569
4670### How to use
0 commit comments