Skip to content

Commit 802d0f9

Browse files
committed
Write /tmp/app-initialized from Fastboot-side
1 parent b5a471d commit 802d0f9

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

fastboot.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
11
'use strict';
22

3+
const fs = require('fs');
34
const FastBootAppServer = require('fastboot-app-server');
45

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+
524
let server = new FastBootAppServer({
625
distPath: 'dist',
726
port: 9000,
827
});
928

29+
if (!cluster.isWorker) {
30+
writeAppInitializedWhenReady();
31+
}
32+
1033
server.start();

src/bin/server.rs

Lines changed: 2 additions & 2 deletions
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)