Skip to content

Commit cff7481

Browse files
committed
Write /tmp/app-initialized from Fastboot-side
1 parent a78d12f commit cff7481

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

fastboot.js

+25
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
1+
/* eslint-disable no-console */
2+
13
'use strict';
24

5+
const fs = require('fs');
36
const FastBootAppServer = require('fastboot-app-server');
47

8+
// because fastboot-app-server uses cluster, but it might change in future
9+
const cluster = require('cluster');
10+
11+
function writeAppInitializedWhenReady() {
12+
let timeout;
13+
14+
timeout = setInterval(function() {
15+
console.log('waiting backend');
16+
if (fs.existsSync('/tmp/backend-initialized')) {
17+
console.log('backend is up. let heroku know the app is ready');
18+
fs.writeFileSync('/tmp/app-initialized', 'hello');
19+
clearInterval(timeout);
20+
} else {
21+
console.log('backend is still not up');
22+
}
23+
}, 1000);
24+
}
25+
526
let server = new FastBootAppServer({
627
distPath: 'dist',
728
port: 9000,
829
});
930

31+
if (!cluster.isWorker) {
32+
writeAppInitializedWhenReady();
33+
}
34+
1035
server.start();

src/bin/server.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ fn main() {
102102
// Creating this file tells heroku to tell nginx that the application is ready
103103
// to receive traffic.
104104
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();
107107
}
108108

109109
// Block the main thread until the server has shutdown

0 commit comments

Comments
 (0)