-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable Fastboot and run its Node server from Procfile
USE_FASTBOOT environment variable is used to enable Fastboot. The number of workers configurable through WEB_CONCURRENCY. https://devcenter.heroku.com/articles/node-memory-use#running-multiple-processes
- Loading branch information
Showing
8 changed files
with
111 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
release: bin/diesel migration run | ||
web: bin/start-nginx ./target/release/server | ||
web: ./script/start-web.sh | ||
background_worker: ./target/release/background-worker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* eslint-disable no-console */ | ||
|
||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const os = require('os'); | ||
const FastBootAppServer = require('fastboot-app-server'); | ||
|
||
// because fastboot-app-server uses cluster, but it might change in future | ||
const cluster = require('cluster'); | ||
|
||
class LoggerWithoutTimestamp { | ||
constructor() { | ||
this.prefix = cluster.isMaster ? 'master' : 'worker'; | ||
} | ||
writeLine() { | ||
this._write('info', Array.prototype.slice.apply(arguments)); | ||
} | ||
|
||
writeError() { | ||
this._write('error', Array.prototype.slice.apply(arguments)); | ||
} | ||
|
||
_write(level, args) { | ||
args[0] = `[${level}][${this.prefix}] ${args[0]}`; | ||
console.log.apply(console, args); | ||
} | ||
} | ||
|
||
function writeAppInitializedWhenReady(logger) { | ||
let timeout; | ||
|
||
timeout = setInterval(function() { | ||
logger.writeLine('waiting backend'); | ||
if (fs.existsSync('/tmp/backend-initialized')) { | ||
logger.writeLine('backend is up. let heroku know the app is ready'); | ||
fs.writeFileSync('/tmp/app-initialized', 'hello'); | ||
clearInterval(timeout); | ||
} else { | ||
logger.writeLine('backend is still not up'); | ||
} | ||
}, 1000); | ||
} | ||
|
||
var logger = new LoggerWithoutTimestamp(); | ||
|
||
logger.writeLine(`${os.cpus().length} cores available`); | ||
|
||
let workerCount = process.env.WEB_CONCURRENCY || 1; | ||
|
||
let server = new FastBootAppServer({ | ||
distPath: 'dist', | ||
port: 9000, | ||
ui: logger, | ||
workerCount: workerCount, | ||
}); | ||
|
||
if (!cluster.isWorker) { | ||
writeAppInitializedWhenReady(logger); | ||
} | ||
|
||
server.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#! /bin/sh | ||
set -ue | ||
|
||
export FASTBOOT_DISABLED | ||
|
||
if [ "${USE_FASTBOOT:-0}" = '1' ]; then | ||
unset FASTBOOT_DISABLED | ||
else | ||
FASTBOOT_DISABLED=1 | ||
fi | ||
|
||
ember "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#! /bin/sh | ||
set -ue | ||
|
||
if [ "${USE_FASTBOOT:-0}" = 1 ]; then | ||
export USE_FASTBOOT=1 | ||
node --optimize_for_size --max_old_space_size=200 fastboot.js & | ||
bin/start-nginx ./target/release/server & | ||
wait -n | ||
else | ||
unset USE_FASTBOOT | ||
bin/start-nginx ./target/release/server | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters