'Why can't my app run on the intended port in Heroku?
I can't figure out what is the problem with heroku, I've spent 2 days trying to figure out what this error means to no avail.
2021-07-18T04:27:08.741998+00:00 app[web.1]: {"level":30,"time":1626582428741,"pid":44,"hostname":"98a3475f-ac16-4dfa-91e0-46d53d3b5e4c","msg":"Server listening at http://127.0.0.1:34196"}
Server is running as you can see, but when i tried to access my app from the web. This happens..
2021-07-18T04:27:56.941807+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
I have no clue what the problem is. My app is clearly running on the intended PORT as Heroku assigned it to be.
package.json
"scripts": {
"test": "npm run build:ts && tsc -p test/tsconfig.test.json && cross-env TS_NODE_FILES=true tap --ts test/**/*.test.ts",
"start": "npm run build:ts && fastify start -l info dist/app.js",
"build:ts": "tsc",
"dev": "tsc && concurrently -k -p \"[{name}]\" -n \"TypeScript,App\" -c \"yellow.bold,cyan.bold\" \"tsc -w\" \"fastify start --ignore-watch=.ts$ -w -l info -P dist/app.js\"",
"database": "npx prisma migrate dev && npx prisma db seed --preview-feature" },
here's the log from heroku logs --tail
2021-07-19T04:34:45.411610+00:00 heroku[web.1]: Stopping process with SIGKILL
2021-07-19T04:34:45.535520+00:00 heroku[web.1]: Process exited with status 137
2021-07-19T04:34:45.641077+00:00 heroku[web.1]: State changed from starting to crashed
2021-07-19T04:34:45.648836+00:00 heroku[web.1]: State changed from crashed to starting
2021-07-19T04:34:59.197914+00:00 heroku[web.1]: Starting process with command `npm start`
2021-07-19T04:35:02.499184+00:00 app[web.1]:
2021-07-19T04:35:02.499211+00:00 app[web.1]: > [email protected] start /app
2021-07-19T04:35:02.499211+00:00 app[web.1]: > fastify start -l info dist/app.js
2021-07-19T04:35:02.499212+00:00 app[web.1]:
2021-07-19T04:35:03.830676+00:00 app[web.1]: {"level":40,"time":1626669303829,"pid":21,"hostname":"5b062824-4105-40ff-87b7-5846163fdac5","msg":"Allowing all origins"}
2021-07-19T04:35:03.856136+00:00 app[web.1]: {"level":40,"time":1626669303855,"pid":21,"hostname":"5b062824-4105-40ff-87b7-5846163fdac5","msg":"\"root\" path \"/app/assets\" must exist"}
2021-07-19T04:35:05.924577+00:00 app[web.1]: {"level":30,"time":1626669305924,"pid":21,"hostname":"5b062824-4105-40ff-87b7-5846163fdac5","msg":"Server listening at http://127.0.0.1:42948"}
2021-07-19T04:35:59.304046+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2021-07-19T04:35:59.382557+00:00 heroku[web.1]: Stopping process with SIGKILL
2021-07-19T04:35:59.486461+00:00 heroku[web.1]: Process exited with status 137
2021-07-19T04:35:59.559137+00:00 heroku[web.1]: State changed from starting to crashed
Notice the app ran just fine, but after a while heroku just stopped working indicated from heroku[web.1] after the app started, which is app[web.1]
Solution 1:[1]
Heroku can only accept applications that's running on 0.0.0.0:{whatever port they assign}. My Fasitfy app was running on 127.0.0.1, which is not the same as 0.0.0.0 apparently. Nevertheless, Heroku doesn't accept any port other than 0.0.0.0
Solution 2:[2]
You call tsc
and it take along time to build.
Change build:ts
to build
and remove npm run build:ts
in start
script:
Document here
{
"name": "something",
"others key": "here",
"scripts": {
"start":"fastify start -l info dist/app.js",
"build": "tsc",
"others script":"echo 'others'",
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | hong4rc |