@@ -10,206 +10,203 @@ This is a Layout which will include two Podlets:
10
10
<Tabs >
11
11
<TabItem value = " express" label = " Express" default >
12
12
13
- ``` js
14
- import express from ' express' ;
15
- import Layout from ' @podium/layout' ;
13
+ ``` js
14
+ import express from ' express' ;
15
+ import Layout from ' @podium/layout' ;
16
16
17
- const layout = new Layout ({
18
- name: ' myLayout' ,
19
- pathname: ' /' ,
20
- });
17
+ const layout = new Layout ({
18
+ name: ' myLayout' ,
19
+ pathname: ' /' ,
20
+ });
21
21
22
- const podletA = layout .client .register ({
23
- name: ' myPodletA' ,
24
- uri: ' http://localhost:7100/manifest.json' ,
25
- });
22
+ const podletA = layout .client .register ({
23
+ name: ' myPodletA' ,
24
+ uri: ' http://localhost:7100/manifest.json' ,
25
+ });
26
26
27
- const podletB = layout .client .register ({
28
- name: ' myPodletB' ,
29
- uri: ' http://localhost:7200/manifest.json' ,
30
- });
27
+ const podletB = layout .client .register ({
28
+ name: ' myPodletB' ,
29
+ uri: ' http://localhost:7200/manifest.json' ,
30
+ });
31
31
32
- const app = express ();
33
- app .use (layout .middleware ());
32
+ const app = express ();
33
+ app .use (layout .middleware ());
34
34
35
- app .get (layout .pathname (), async (req , res , next ) => {
36
- const incoming = res .locals .podium ;
35
+ app .get (layout .pathname (), async (req , res , next ) => {
36
+ const incoming = res .locals .podium ;
37
37
38
- const [a , b ] = await Promise .all ([
39
- podletA .fetch (incoming),
40
- podletB .fetch (incoming),
41
- ]);
38
+ const [a , b ] = await Promise .all ([
39
+ podletA .fetch (incoming),
40
+ podletB .fetch (incoming),
41
+ ]);
42
42
43
- res .podiumSend (`
44
- <section>${ a .content } </section>
45
- <section>${ b .content } </section>
46
- ` );
47
- });
43
+ res .podiumSend (`
44
+ <section>${ a .content } </section>
45
+ <section>${ b .content } </section>
46
+ ` );
47
+ });
48
48
49
- app .listen (7000 );
50
- ```
49
+ app .listen (7000 );
50
+ ```
51
51
52
52
</TabItem >
53
53
<TabItem value = " hapi" label = " Hapi" >
54
54
55
- ``` js
56
- import HapiLayout from ' @podium/hapi-layout' ;
57
- import Layout from ' @podium/layout' ;
58
- import Hapi from ' hapi' ;
59
-
60
- const app = Hapi .Server ({
61
- host: ' localhost' ,
62
- port: 7000 ,
63
- });
64
-
65
- const layout = new Layout ({
66
- name: ' myLayout' ,
67
- pathname: ' /' ,
68
- });
69
-
70
- const podletA = layout .client .register ({
71
- name: ' myPodletA' ,
72
- uri: ' http://localhost:7100/manifest.json' ,
73
- });
74
-
75
- const podletB = layout .client .register ({
76
- name: ' myPodletB' ,
77
- uri: ' http://localhost:7200/manifest.json' ,
78
- });
79
-
80
- app .register ({
81
- plugin: new HapiLayout (),
82
- options: layout,
83
- });
84
-
85
- app .route ({
86
- method: ' GET' ,
87
- path: layout .pathname (),
88
- handler : (request , h ) => {
89
- const incoming = request .app .podium ;
90
-
91
- const [a , b ] = await Promise .all ([
92
- podletA .fetch (incoming),
93
- podletB .fetch (incoming),
94
- ]);
95
-
96
- h .podiumSend (`
97
- <section>${ a .content } </section>
98
- <section>${ b .content } </section>
99
- ` );
100
-
101
- },
102
- });
103
-
104
- app .start ();
105
- ```
55
+ ``` js
56
+ import HapiLayout from ' @podium/hapi-layout' ;
57
+ import Layout from ' @podium/layout' ;
58
+ import Hapi from ' hapi' ;
59
+
60
+ const app = Hapi .Server ({
61
+ host: ' localhost' ,
62
+ port: 7000 ,
63
+ });
64
+
65
+ const layout = new Layout ({
66
+ name: ' myLayout' ,
67
+ pathname: ' /' ,
68
+ });
69
+
70
+ const podletA = layout .client .register ({
71
+ name: ' myPodletA' ,
72
+ uri: ' http://localhost:7100/manifest.json' ,
73
+ });
74
+
75
+ const podletB = layout .client .register ({
76
+ name: ' myPodletB' ,
77
+ uri: ' http://localhost:7200/manifest.json' ,
78
+ });
79
+
80
+ app .register ({
81
+ plugin: new HapiLayout (),
82
+ options: layout,
83
+ });
84
+
85
+ app .route ({
86
+ method: ' GET' ,
87
+ path: layout .pathname (),
88
+ handler : (request , h ) => {
89
+ const incoming = request .app .podium ;
90
+ const [a , b ] = await Promise .all ([
91
+ podletA .fetch (incoming),
92
+ podletB .fetch (incoming),
93
+ ]);
94
+ h .podiumSend (`
95
+ <section>${ a .content } </section>
96
+ <section>${ b .content } </section>
97
+ ` );
98
+ },
99
+ });
100
+
101
+ app .start ();
102
+ ```
106
103
107
104
</TabItem >
108
105
<TabItem value = " fastify" label = " Fastify" >
109
106
110
107
111
- ``` js
112
- import fastifyLayout from ' @podium/fastify-layout' ;
113
- import fastify from ' fastify' ;
114
- import Layout from ' @podium/layout' ;
115
-
116
- const app = fastify ();
117
-
118
- const layout = new Layout ({
119
- name: ' myLayout' ,
120
- pathname: ' /' ,
121
- });
122
-
123
- const podletA = layout .client .register ({
124
- name: ' myPodletA' ,
125
- uri: ' http://localhost:7100/manifest.json' ,
126
- });
127
-
128
- const podletB = layout .client .register ({
129
- name: ' myPodletB' ,
130
- uri: ' http://localhost:7200/manifest.json' ,
131
- });
132
-
133
- app .register (fastifyLayout, layout);
134
-
135
- app .get (layout .pathname (), async (request , reply ) => {
136
- const incoming = reply .app .podium ;
137
-
138
- const [a , b ] = await Promise .all ([
139
- podletA .fetch (incoming),
140
- podletB .fetch (incoming),
141
- ]);
142
-
143
- reply .podiumSend (`
144
- <section>${ a .content } </section>
145
- <section>${ b .content } </section>
146
- ` );
147
- });
148
-
149
- const start = async () => {
150
- try {
151
- await app .listen (7000 );
152
- app .log .info (` server listening on ${ app .server .address ().port } ` );
153
- } catch (err) {
154
- app .log .error (err);
155
- process .exit (1 );
156
- }
108
+ ``` js
109
+ import fastifyLayout from ' @podium/fastify-layout' ;
110
+ import fastify from ' fastify' ;
111
+ import Layout from ' @podium/layout' ;
112
+
113
+ const app = fastify ();
114
+
115
+ const layout = new Layout ({
116
+ name: ' myLayout' ,
117
+ pathname: ' /' ,
118
+ });
119
+
120
+ const podletA = layout .client .register ({
121
+ name: ' myPodletA' ,
122
+ uri: ' http://localhost:7100/manifest.json' ,
123
+ });
124
+
125
+ const podletB = layout .client .register ({
126
+ name: ' myPodletB' ,
127
+ uri: ' http://localhost:7200/manifest.json' ,
128
+ });
129
+
130
+ app .register (fastifyLayout, layout);
131
+
132
+ app .get (layout .pathname (), async (request , reply ) => {
133
+ const incoming = reply .app .podium ;
134
+
135
+ const [a , b ] = await Promise .all ([
136
+ podletA .fetch (incoming),
137
+ podletB .fetch (incoming),
138
+ ]);
139
+
140
+ reply .podiumSend (`
141
+ <section>${ a .content } </section>
142
+ <section>${ b .content } </section>
143
+ ` );
144
+ });
145
+
146
+ const start = async () => {
147
+ try {
148
+ await app .listen (7000 );
149
+ app .log .info (` server listening on ${ app .server .address ().port } ` );
150
+ } catch (err) {
151
+ app .log .error (err);
152
+ process .exit (1 );
157
153
}
158
- start ();
159
- ```
154
+ }
155
+ start ();
156
+ ```
160
157
161
158
162
159
</TabItem >
163
160
<TabItem value = " http" label = " Http" >
164
161
165
- ``` js
166
- import { HttpIncoming } from ' @podium/utils' ;
167
- import Layout from ' @podium/layout' ;
168
- import http from ' http' ;
169
-
170
- const layout = new Layout ({
171
- name: ' myLayout' ,
172
- pathname: ' /' ,
173
- });
174
-
175
- const podletA = layout .client .register ({
176
- name: ' myPodletA' ,
177
- uri: ' http://localhost:7100/manifest.json' ,
178
- });
179
-
180
- const podletB = layout .client .register ({
181
- name: ' myPodletB' ,
182
- uri: ' http://localhost:7200/manifest.json' ,
183
- });
184
-
185
- const server = http .createServer (async (req , res ) => {
186
- let incoming = new HttpIncoming (req, res);
187
- incoming = await layout .process (incoming);
188
-
189
- if (incoming .url .pathname === layout .pathname ()) {
190
-
191
- const [ a , b ] = await Promise . all ([
192
- podletA .fetch (incoming),
193
- podletB . fetch (incoming),
194
- ]);
195
-
196
- res .statusCode = 200 ;
197
- res . setHeader ( ' Content-Type ' , ' text/html ' );
198
-
199
- res . end ( podlet . render (incoming, `
200
- <section>${ a .content } </section>
201
- <section> ${ b . content } </section>
202
- ` ));
203
- return ;
204
- }
205
-
206
- res .statusCode = 404 ;
207
- res .setHeader (' Content-Type' , ' text/plain' );
208
- res .end (' Not found' );
209
- });
210
-
211
- server .listen (7000 );
212
- ```
162
+ ``` js
163
+ import { HttpIncoming } from ' @podium/utils' ;
164
+ import Layout from ' @podium/layout' ;
165
+ import http from ' http' ;
166
+
167
+ const layout = new Layout ({
168
+ name: ' myLayout' ,
169
+ pathname: ' /' ,
170
+ });
171
+
172
+ const podletA = layout .client .register ({
173
+ name: ' myPodletA' ,
174
+ uri: ' http://localhost:7100/manifest.json' ,
175
+ });
176
+
177
+ const podletB = layout .client .register ({
178
+ name: ' myPodletB' ,
179
+ uri: ' http://localhost:7200/manifest.json' ,
180
+ });
181
+
182
+ const server = http .createServer (async (req , res ) => {
183
+ let incoming = new HttpIncoming (req, res);
184
+ incoming = await layout .process (incoming);
185
+
186
+ if (incoming .url .pathname === layout .pathname ()) {
187
+ const [ a , b ] = await Promise . all ([
188
+ podletA . fetch (incoming),
189
+ podletB .fetch (incoming),
190
+ ]);
191
+
192
+ res . statusCode = 200 ;
193
+ res .setHeader ( ' Content-Type ' , ' text/html ' ) ;
194
+
195
+ res . end ( podlet . render (incoming, `
196
+ <section> ${ a . content } </section>
197
+ <section>${ b .content } </section>
198
+ ` ));
199
+
200
+ return ;
201
+ }
202
+
203
+ res .statusCode = 404 ;
204
+ res .setHeader (' Content-Type' , ' text/plain' );
205
+ res .end (' Not found' );
206
+ });
207
+
208
+ server .listen (7000 );
209
+ ```
213
210
214
211
</TabItem >
215
212
0 commit comments