File tree 2 files changed +25
-2
lines changed
2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
+ const fs = require ( 'fs' ) ;
3
4
const FastBootAppServer = require ( 'fastboot-app-server' ) ;
4
5
6
+ // because fastboot-app-server uses cluster, but it might change in future
7
+ const cluster = require ( 'cluster' ) ;
8
+
9
+ function writeAppInitializedWhenReady ( ) {
10
+ let timeout ;
11
+
12
+ timeout = setInterval ( function ( ) {
13
+ console . log ( 'waiting backend' ) ;
14
+ if ( fs . existsSync ( '/tmp/backend-initialized' ) ) {
15
+ console . log ( 'backend is up. let heroku know the app is ready' ) ;
16
+ fs . writeFileSync ( '/tmp/app-initialized' , 'hello' ) ;
17
+ clearInterval ( timeout ) ;
18
+ } else {
19
+ console . log ( 'backend is still not up' ) ;
20
+ }
21
+ } , 1000 ) ;
22
+ }
23
+
5
24
let server = new FastBootAppServer ( {
6
25
distPath : 'dist' ,
7
26
port : 9000 ,
8
27
} ) ;
9
28
29
+ if ( ! cluster . isWorker ) {
30
+ writeAppInitializedWhenReady ( ) ;
31
+ }
32
+
10
33
server . start ( ) ;
Original file line number Diff line number Diff line change @@ -102,8 +102,8 @@ fn main() {
102
102
// Creating this file tells heroku to tell nginx that the application is ready
103
103
// to receive traffic.
104
104
if heroku {
105
- println ! ( "Writing to /tmp/app -initialized" ) ;
106
- File :: create ( "/tmp/app -initialized" ) . unwrap ( ) ;
105
+ println ! ( "Writing to /tmp/backend -initialized" ) ;
106
+ File :: create ( "/tmp/backend -initialized" ) . unwrap ( ) ;
107
107
}
108
108
109
109
// Block the main thread until the server has shutdown
You can’t perform that action at this time.
0 commit comments