I am deploying to Heroku, and I included the following scripts in my package.json
:
"scripts": {
"heroku-postbuild": "yarn run build"
"start": "NODE_ENV=production node build/server.js"
}
Unfortunately, the PORT
env var is not known at build time and is instead assigned by Heroku at run time, and since razzle needs to know the port at build time, it means I must build before starting the server. With that in mind, I tried changing my scripts to look like the following:
"scripts": {
"start": "NODE_ENV=production yarn run build && node build/server.js"
}
Unfortunately, that takes too long and ends up binding after the 60 second Heroku timeout:
2017-09-06T01:23:13.536789+00:00 app[web.1]: Compiling client...
2017-09-06T01:23:14.395857+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2017-09-06T01:23:14.395963+00:00 heroku[web.1]: Stopping process with SIGKILL
2017-09-06T01:23:14.499913+00:00 heroku[web.1]: Process exited with status 137
2017-09-06T01:23:14.509625+00:00 heroku[web.1]: State changed from starting to crashed
Is there a way that we could not require the port at build time? Why is it needed then anyway?
You can use razzle-heroku :) It extends the default razzle config to make it works on heroku.
Ahh, didn't know about that, thanks for pointing it out! If I already have razzle.config.js
with a custom modify
function, is there a way I can still use that while also making use of razzle-heroku?
// razzle.config.js
const razzleHeroku = require("razzle-heroku")
module.exports = {
modify: (config, {target, dev}, webpack) => {
config = razzleHeroku(config, {target, dev}, webpack)
// do something to config
return config
},
}
Maybe something like this ?
Most helpful comment
Maybe something like this ?