File tree Expand file tree Collapse file tree 6 files changed +116
-6
lines changed
federated-css-react-ssr/shell-apps
jss-styled-components-css-module/server
jss-styled-components/server Expand file tree Collapse file tree 6 files changed +116
-6
lines changed Original file line number Diff line number Diff line change 1
1
const express = require ( 'express' ) ;
2
2
const initMiddleware = require ( './middleware' ) ;
3
+ const fetch = require ( 'node-fetch' ) ;
3
4
4
5
const app = express ( ) ;
5
6
const PORT = 4000 ;
6
7
7
- const done = ( ) => {
8
+ async function waitUrl ( url , timeout = 120000 ) {
9
+ const start = Date . now ( ) ;
10
+ // Retry until the remoteEntry.js is available over HTTP
11
+ /* eslint-disable no-await-in-loop */
12
+ while ( true ) {
13
+ try {
14
+ const res = await fetch ( url ) ;
15
+ if ( res . ok ) return ;
16
+ } catch ( _ ) { }
17
+
18
+ if ( Date . now ( ) - start > timeout ) {
19
+ throw new Error ( `prewarm timeout for ${ url } ` ) ;
20
+ }
21
+ await new Promise ( r => setTimeout ( r , 1000 ) ) ;
22
+ }
23
+ }
24
+
25
+ const done = async ( ) => {
26
+ // Ensure remotes are reachable before the first SSR render
27
+ await Promise . all ( [
28
+ waitUrl ( 'http://localhost:3001/server/remoteEntry.js' ) ,
29
+ waitUrl ( 'http://localhost:3002/server/remoteEntry.js' ) ,
30
+ ] ) ;
31
+
8
32
app . listen ( PORT , ( ) => {
9
33
console . info (
10
34
`[${ new Date ( ) . toISOString ( ) } ]` ,
Original file line number Diff line number Diff line change 1
1
const express = require ( 'express' ) ;
2
2
const initMiddleware = require ( './middleware' ) ;
3
+ const fetch = require ( 'node-fetch' ) ;
3
4
4
5
const app = express ( ) ;
5
6
const PORT = 4001 ;
6
7
7
- const done = ( ) => {
8
+ async function waitUrl ( url , timeout = 120000 ) {
9
+ const start = Date . now ( ) ;
10
+ while ( true ) {
11
+ try {
12
+ const res = await fetch ( url ) ;
13
+ if ( res . ok ) return ;
14
+ } catch ( _ ) { }
15
+ if ( Date . now ( ) - start > timeout ) throw new Error ( `prewarm timeout for ${ url } ` ) ;
16
+ await new Promise ( r => setTimeout ( r , 1000 ) ) ;
17
+ }
18
+ }
19
+
20
+ const done = async ( ) => {
21
+ await Promise . all ( [
22
+ waitUrl ( 'http://localhost:3001/server/remoteEntry.js' ) ,
23
+ waitUrl ( 'http://localhost:3004/server/remoteEntry.js' ) ,
24
+ ] ) ;
8
25
app . listen ( PORT , ( ) => {
9
26
console . info (
10
27
`[${ new Date ( ) . toISOString ( ) } ]` ,
Original file line number Diff line number Diff line change 1
1
const express = require ( 'express' ) ;
2
2
const initMiddleware = require ( './middleware' ) ;
3
+ const fetch = require ( 'node-fetch' ) ;
3
4
4
5
const app = express ( ) ;
5
6
const PORT = 4003 ;
6
7
7
- const done = ( ) => {
8
+ async function waitUrl ( url , timeout = 120000 ) {
9
+ const start = Date . now ( ) ;
10
+ while ( true ) {
11
+ try {
12
+ const res = await fetch ( url ) ;
13
+ if ( res . ok ) return ;
14
+ } catch ( _ ) { }
15
+ if ( Date . now ( ) - start > timeout ) throw new Error ( `prewarm timeout for ${ url } ` ) ;
16
+ await new Promise ( r => setTimeout ( r , 1000 ) ) ;
17
+ }
18
+ }
19
+
20
+ const done = async ( ) => {
21
+ await Promise . all ( [
22
+ waitUrl ( 'http://localhost:3005/server/remoteEntry.js' ) ,
23
+ waitUrl ( 'http://localhost:3002/server/remoteEntry.js' ) ,
24
+ waitUrl ( 'http://localhost:3006/server/remoteEntry.js' ) ,
25
+ ] ) ;
8
26
app . listen ( PORT , ( ) => {
9
27
console . info (
10
28
`[${ new Date ( ) . toISOString ( ) } ]` ,
Original file line number Diff line number Diff line change 1
1
const express = require ( 'express' ) ;
2
2
const initMiddleware = require ( './middleware' ) ;
3
+ const fetch = require ( 'node-fetch' ) ;
3
4
4
5
const app = express ( ) ;
5
6
const PORT = 4002 ;
6
7
7
- const done = ( ) => {
8
+ async function waitUrl ( url , timeout = 120000 ) {
9
+ const start = Date . now ( ) ;
10
+ while ( true ) {
11
+ try {
12
+ const res = await fetch ( url ) ;
13
+ if ( res . ok ) return ;
14
+ } catch ( _ ) { }
15
+ if ( Date . now ( ) - start > timeout ) throw new Error ( `prewarm timeout for ${ url } ` ) ;
16
+ await new Promise ( r => setTimeout ( r , 1000 ) ) ;
17
+ }
18
+ }
19
+
20
+ const done = async ( ) => {
21
+ await Promise . all ( [
22
+ waitUrl ( 'http://localhost:3005/server/remoteEntry.js' ) ,
23
+ waitUrl ( 'http://localhost:3002/server/remoteEntry.js' ) ,
24
+ ] ) ;
8
25
app . listen ( PORT , ( ) => {
9
26
console . info (
10
27
`[${ new Date ( ) . toISOString ( ) } ]` ,
Original file line number Diff line number Diff line change 1
1
const express = require ( 'express' ) ;
2
2
const initMiddleware = require ( './middleware' ) ;
3
+ const fetch = require ( 'node-fetch' ) ;
3
4
4
5
const app = express ( ) ;
5
6
const PORT = 4004 ;
6
7
7
- const done = ( ) => {
8
+ async function waitUrl ( url , timeout = 120000 ) {
9
+ const start = Date . now ( ) ;
10
+ while ( true ) {
11
+ try {
12
+ const res = await fetch ( url ) ;
13
+ if ( res . ok ) return ;
14
+ } catch ( _ ) { }
15
+ if ( Date . now ( ) - start > timeout ) throw new Error ( `prewarm timeout for ${ url } ` ) ;
16
+ await new Promise ( r => setTimeout ( r , 1000 ) ) ;
17
+ }
18
+ }
19
+
20
+ const done = async ( ) => {
21
+ await Promise . all ( [
22
+ waitUrl ( 'http://localhost:3007/server/remoteEntry.js' ) ,
23
+ waitUrl ( 'http://localhost:3004/server/remoteEntry.js' ) ,
24
+ ] ) ;
8
25
app . listen ( PORT , ( ) => {
9
26
console . info (
10
27
`[${ new Date ( ) . toISOString ( ) } ]` ,
Original file line number Diff line number Diff line change 1
1
const express = require ( 'express' ) ;
2
2
const initMiddleware = require ( './middleware' ) ;
3
+ const fetch = require ( 'node-fetch' ) ;
3
4
4
5
const app = express ( ) ;
5
6
const PORT = 4005 ;
6
7
7
- const done = ( ) => {
8
+ async function waitUrl ( url , timeout = 120000 ) {
9
+ const start = Date . now ( ) ;
10
+ while ( true ) {
11
+ try {
12
+ const res = await fetch ( url ) ;
13
+ if ( res . ok ) return ;
14
+ } catch ( _ ) { }
15
+ if ( Date . now ( ) - start > timeout ) throw new Error ( `prewarm timeout for ${ url } ` ) ;
16
+ await new Promise ( r => setTimeout ( r , 1000 ) ) ;
17
+ }
18
+ }
19
+
20
+ const done = async ( ) => {
21
+ await Promise . all ( [
22
+ waitUrl ( 'http://localhost:3003/server/remoteEntry.js' ) ,
23
+ waitUrl ( 'http://localhost:3004/server/remoteEntry.js' ) ,
24
+ ] ) ;
8
25
app . listen ( PORT , ( ) => {
9
26
console . info (
10
27
`[${ new Date ( ) . toISOString ( ) } ]` ,
You can’t perform that action at this time.
0 commit comments