@@ -8,43 +8,85 @@ neet to open the plugin for using
8
8
9
9
### extends
10
10
11
- - ctx.render(filepath,props) Render the ` filepath ` by proprs and set the result as ` ctx.body ` value
12
- - ctx.renderView(filepath,props) Render the ` filepath ` by proprs and return result for SSR
11
+ - ctx.ssr(filepath,props) Render the ` filepath ` by proprs and return result for SSR, ` filepath ` is absolute path
13
12
14
13
## Configure
15
14
16
15
``` js
16
+ // config/pulgin.js
17
17
exports .beidou = {
18
18
enable: true ,
19
19
package: ' egg-beidou' ,
20
20
};
21
21
22
22
// config.default.js
23
23
exports .beidou = {
24
- static: true , // whether use static render for SSR
24
+ static: false , // whether use static render for SSR
25
25
stream: false , // whether use stream render for SSR
26
+ cache: true , // whether open require cache
27
+ onError : function (error ){ // call the function when render occur error
28
+ // do something
29
+ },
30
+ view: " /home/admin/project/" ,
31
+ extensions: [ ' .js' , ' jsx' , ' .ts' , ' .tsx' ] , // file suffix
26
32
};
27
33
```
28
34
29
35
## Example
30
36
31
37
> see more example to test/exmaple folder
32
38
39
+ ### case1 : render packaged code
33
40
``` js
34
41
// Controller
35
42
' use strict' ;
36
43
37
44
exports .index = async function (ctx ) {
38
- await ctx .render (' simple/index.js' , {
45
+ await ctx .ssr (' simple/index.js' , {
39
46
data: {
40
47
text: ' hello world!' ,
41
48
},
42
49
});
43
50
};
44
51
45
- // if you need pass server data to render
52
+ // put your data into react render for react this.props
46
53
exports .simple = async function (ctx ) {
47
- ctx .body = await ctx .renderView (' simple/index.js' , {
54
+ ctx .body = await ctx .ssr (' simple/index.js' , {
55
+ data: {
56
+ text: ' hello world!' ,
57
+ },
58
+ });
59
+ };
60
+
61
+ // if you need to pass absolute path
62
+ exports .test = async function (ctx ) {
63
+ ctx .body = await ctx .ssr (' /usr/local/project/simple/index.js' , {
64
+ data: {
65
+ text: ' hello world!' ,
66
+ },
67
+ });
68
+ };
69
+ ```
70
+
71
+ ### case2: render react native code
72
+ > The scheme of rendering React code by this plug-in is consistent with that of Beidou isomorphic framework, which can be used with reference to Beidou isomorphic framework document.
73
+
74
+ ``` js
75
+ // config/plugin.js
76
+ // install egg-plugin: beidou-isomorphic & beidou-webpack and enable plugin
77
+ isomorphic: {
78
+ enable: true ,
79
+ package: ' beidou-isomorphic' ,
80
+ },
81
+ webpack: {
82
+ enable: true ,
83
+ package: ' beidou-webpack' ,
84
+ env: [ ' local' , ' unittest' ],
85
+ }
86
+
87
+ // controller/index.js
88
+ exports .simple = async function (ctx ) {
89
+ ctx .body = await ctx .ssr (' simple/index.jsx' , {
48
90
data: {
49
91
text: ' hello world!' ,
50
92
},
0 commit comments