I deploy a NestJS Application to Heroku and get H10 Error
Log:
2020-05-07T13:12:51.967622+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-07T13:15:14.556288+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=scalenode.herokuapp.com request_id=535e5643-26ad-4fbe-acf3-7f805c8c463c fwd="91.64.79.140" dyno= connect= service= status=503 bytes= protocol=https
Its stunning, because the Error comes because of GET Request. Node has been compiled successfully. I deployed via HerokuCli and Github. Both has the same result. But if I test it with HerokuCli locally with heroku local web, it works.
It does not seems to be a deployment error itself, its seems to be the route / cant be resolved so the app crashes. When I open the app in browser after successfully deploy, it seems to be a timeout.
Here is the Repo. I have a 'Hello World' string on / route. I cant find out whats wrong.
I use a Procfile for the instance, which seems to be fine:
web: node dist/main.js
EDIT:
I tried to have a static HTML Response and tried stable Node Version 12.x.
I dont get it
2020-05-07T14:22:40.862206+00:00 app[web.1]: [32m[Nest] 4 - [39m05/07/2020, 2:22:40 PM [38;5;3m[RoutesResolver] [39m[32mAppController {}:[39m[38;5;3m +6ms[39m
2020-05-07T14:22:40.865503+00:00 app[web.1]: [32m[Nest] 4 - [39m05/07/2020, 2:22:40 PM [38;5;3m[RouterExplorer] [39m[32mMapped {, GET} route[39m[38;5;3m +3ms[39m
2020-05-07T14:22:40.865886+00:00 app[web.1]: [32m[Nest] 4 - [39m05/07/2020, 2:22:40 PM [38;5;3m[RoutesResolver] [39m[32mAuthController {}:[39m[38;5;3m +0ms[39m
2020-05-07T14:22:40.867140+00:00 app[web.1]: [32m[Nest] 4 - [39m05/07/2020, 2:22:40 PM [38;5;3m[RouterExplorer] [39m[32mMapped {/auth/login, POST} route[39m[38;5;3m +2ms[39m
2020-05-07T14:22:40.867778+00:00 app[web.1]: [32m[Nest] 4 - [39m05/07/2020, 2:22:40 PM [38;5;3m[RouterExplorer] [39m[32mMapped {/profile, GET} route[39m[38;5;3m +0ms[39m
2020-05-07T14:22:40.868162+00:00 app[web.1]: [32m[Nest] 4 - [39m05/07/2020, 2:22:40 PM [38;5;3m[RoutesResolver] [39m[32mFilesController {/files}:[39m[38;5;3m +1ms[39m
2020-05-07T14:22:40.868999+00:00 app[web.1]: [32m[Nest] 4 - [39m05/07/2020, 2:22:40 PM [38;5;3m[RouterExplorer] [39m[32mMapped {/files/upload, POST} route[39m[38;5;3m +0ms[39m
2020-05-07T14:22:40.873240+00:00 app[web.1]: [32m[Nest] 4 - [39m05/07/2020, 2:22:40 PM [38;5;3m[NestApplication] [39m[32mNest application successfully started[39m[38;5;3m +5ms[39m
2020-05-07T14:22:42.000000+00:00 app[api]: Build succeeded
It doesnt work... i cant find more details in logs, nothing more concrete. What the hell is going wrong...
In main.ts, have you tried changing the port number? To something like:
app.listen(parseInt(process.env.PORT) || 3000)
Since Heroku will try to use its own port. Maybe this could work too:
const port: number = parseInt(`${process.env.PORT}`) || 3000;
await app.listen(port);
Did you try setting heroku config variable NPM_CONFIG_PRODUCTION to false?
You can try this by going to your heroku dashboard -> settings -> reveal config vars, and then add the value above.
This error happens mainly because NestJS relies on some devDependencies in your project, and heroku removes devDependencies when building your Nest app if you're building in production mode. Setting NPM_CONFIG_PRODUCTION config to false would include all your dev dependencies in the Nest app's build process, just like building for a development environment. Alternatively, you can selectively move your nest related devDependencies to dependencies in package.json until the problem is gone.
Let me know if it works!
Related
This is the error:
Access to XMLHttpRequest at 'http://cheapandnice-backend.herokuapp.com/api/products/list'
from origin 'http://cheapandnice.herokuapp.com' has been blocked by CORS policy: No 'Access-
Control-Allow-Origin' header is present on the requested resource.
But I've already included the origin with cors:
const app = express();
app.use(
cors({
origin: process.env.ORIGIN,
optionsSuccessStatus: 200,
credentials: true,
})
);
process.env.ORIGIN is http://cheapandnice.herokuapp.com
I've tried with heroku local, which I think runs the code on heroku locally, and everything works just fine. As for my client I served the files locally with "yarn build" and then "serve -d build" and it works.
However this is what I get whem I run heroku restart and heroku logs --tail
2020-05-09T01:57:28.971077+00:00 heroku[web.1]: Restarting
2020-05-09T01:57:28.987996+00:00 heroku[web.1]: State changed from up to starting
2020-05-09T01:57:35.626755+00:00 app[web.1]: Server is running on port 41637
2020-05-09T01:57:35.629379+00:00 app[web.1]: [db] Cannot read property 'split' of null
2020-05-09T01:57:36.571910+00:00 heroku[web.1]: State changed from starting to up
and when I make a request
2020-05-09T02:00:04.559800+00:00 heroku[router]: at=error code=H12 desc="Request timeout"
method=GET path="/api/products/list" host=cheapandnice-backend.herokuapp.com
request_id=98822b44-b339-48ec-b33d-c7dd91e8a380 fwd="186.168.187.244" dyno=web.1 connect=1ms
service=30000ms status=503 bytes=0 protocol=http
I'm using Mongo Atlas
Ok so it turns out it's not a CORS problem. Heroku logs --tails shows this
2020-05-09T01:57:35.629379+00:00 app[web.1]: [db] Cannot read property 'split' of null
I put simple quotes when I configured my ENV variables in heroku
'mongodb+srv://...'
I removed the quotes and it works now
I'm sorry if this question similar with many other. But I have so many try to solve this, but not get the correct code to fix this.
I develop flask application use docker-machine and docker swarm. When I run in my local it work perfectly. But when I try deploy to heroku use heroku.yml I get error
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
I'm new to use heroku, so mybe I miss something. I hope advaced can help to see what I miss.
.
|-- 2019-06-26-17-05-08.076-VBoxSVC-5799.log
|-- app
| |-- app.py
| |-- Dockerfile
| |-- requirements.txt
| '-- static
|-- docker-compose.yml
|-- heroku.yml
|-- nginx
| |-- Dockerfile
| |-- nginx.conf
| '-- smartapp.conf
'-- README.md
./heroku.yml
build:
docker:
web: app/Dockerfile
worker: app/Dockerfile
./app/Dockerfile
# Use an official Python runtime as a parent image
FROM python:3.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 8000 available to the world outside this container
#EXPOSE 8000
# Define environment variable
ENV FLASK_APP=smartapp
ENV FLASK_ENV=development
# Run run.py when the container launches
CMD ["gunicorn", "-b", "0.0.0.0", "app:app"]
./nginx/Dockerfile
FROM nginx
RUN rm /etc/nginx/nginx.conf
COPY nginx.conf /etc/nginx/
RUN rm /etc/nginx/conf.d/default.conf
COPY smartapp.conf /etc/nginx/conf.d/
./app/app.py
from flask import Flask
from redis import Redis, RedisError
import os
import socket
# Connect to Redis
redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)
app = Flask(__name__)
#app.route("/")
def hello():
try:
visits = redis.incr("counter")
except RedisError:
visits = "<i>cannot connect to Redis, counter disabled</i>"
html = "<h3>Hello {name}!</h3>" \
"<b>Hostname:</b> {hostname}<br/>" \
"<b>Visits:</b> {visits}"
return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits)
if __name__ == "__main__":
# Bind to PORT if defined, otherwise default to 5000.
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0:$PORT')
$ heroku logs --tail
2019-06-28T03:47:57.545950+00:00 heroku[web.1]: Starting process with command `gunicorn -b 0.0.0.0 app:app`
2019-06-28T03:47:59.233102+00:00 app[web.1]: [2019-06-28 03:47:59 +0000] [4] [INFO] Starting gunicorn 19.9.0
2019-06-28T03:47:59.233716+00:00 app[web.1]: [2019-06-28 03:47:59 +0000] [4] [INFO] Listening at: http://0.0.0.0:8000 (4)
2019-06-28T03:47:59.233827+00:00 app[web.1]: [2019-06-28 03:47:59 +0000] [4] [INFO] Using worker: sync
2019-06-28T03:47:59.238431+00:00 app[web.1]: [2019-06-28 03:47:59 +0000] [7] [INFO] Booting worker with pid: 7
2019-06-28T03:48:57.898890+00:00 heroku[web.1]: State changed from starting to crashed
2019-06-28T03:48:57.786102+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2019-06-28T03:48:57.786193+00:00 heroku[web.1]: Stopping process with SIGKILL
2019-06-28T03:48:57.883116+00:00 heroku[web.1]: Process exited with status 137
2019-06-28T03:48:58.833786+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=quiet-cove-70697.herokuapp.com request_id=a0fd1087-0ac8-44c8-ac31-cb43a46a9449 fwd="103.7.225.121" dyno= connect= service= status=503 bytes= protocol=https
2019-06-28T03:48:59.820240+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=quiet-cove-70697.herokuapp.com request_id=cd9bce77-f818-4516-b2b0-333ab2b95eea fwd="103.7.225.121" dyno= connect= service= status=503 bytes= protocol=https
2019-06-28T03:49:15.792328+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=quiet-cove-70697.herokuapp.com request_id=4ba13aa2-f739-4792-9859-9ad86d9da38b fwd="103.7.225.121" dyno= connect= service= status=503 bytes= protocol=https
2019-06-28T03:49:16.883549+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=quiet-cove-70697.herokuapp.com request_id=1acbfe60-2023-42d5-8091-826d0156d765 fwd="103.7.225.121" dyno= connect= service= status=503 bytes= protocol=https
2019-06-28T03:55:22.425339+00:00 heroku[web.1]: State changed from crashed to starting
2019-06-28T03:55:25.634810+00:00 heroku[web.1]: Starting process with command `gunicorn -b 0.0.0.0 app:app`
2019-06-28T03:55:27.616318+00:00 app[web.1]: [2019-06-28 03:55:27 +0000] [4] [INFO] Starting gunicorn 19.9.0
2019-06-28T03:55:27.616885+00:00 app[web.1]: [2019-06-28 03:55:27 +0000] [4] [INFO] Listening at: http://0.0.0.0:8000 (4)
2019-06-28T03:55:27.616984+00:00 app[web.1]: [2019-06-28 03:55:27 +0000] [4] [INFO] Using worker: sync
2019-06-28T03:55:27.621084+00:00 app[web.1]: [2019-06-28 03:55:27 +0000] [7] [INFO] Booting worker with pid: 7
2019-06-28T03:56:25.725581+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2019-06-28T03:56:25.725672+00:00 heroku[web.1]: Stopping process with SIGKILL
2019-06-28T03:56:25.821622+00:00 heroku[web.1]: State changed from starting to crashed
2019-06-28T03:56:25.799366+00:00 heroku[web.1]: Process exited with status 137
Thank's
I think you need to pass port not $PORT to your run command :
my_port = '0.0.0.0:' + str(port)
app.run(host=my_port)
you had already assign the variable port the right value.
and you need to EXPOSE the port also in your Dockerfile
After search for my solution, I got this link Adding Gunicorn to your application.
And I update Dockerfile like this:
# Use an official Python runtime as a parent image
FROM python:3.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Define environment variable
ENV FLASK_APP=smartapp
ENV FLASK_ENV=development
# Run run.py when the container launches
CMD ["gunicorn", "app:app"]
I remove this code from last row (see the previos code above):
"-b", "0.0.0.0",
And now my application can run in heroku... (o.0)
Here is an issue I am having with an app on Parse-Server (/Heroku).
I keep getting the message:
WARNING, Unable to connect to 'https://myapp.herokuapp.com/'. Cloud code and push notifications may be unavailable!
Here is the complete log I have when running the command: git push heroku master
2018-02-2...+00:00 app[api]: Build started by user me#xyz.com
2018-02-2...+00:00 app[api]: Deploy bduxedc8 by user me#xyz.com
2018-02-2...+00:00 app[api]: Build succeeded
2018-02-2...+00:00 app[api]: Release v25 created by user me#xyz.com
2018-02-2...+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-02-2...+00:00 heroku[web.1]: Process exited with status 143
2018-02-2...+00:00 heroku[web.1]: Restarting
2018-02-2...+00:00 heroku[web.1]: State changed from up to starting
2018-02-2...+00:00 heroku[web.1]: Starting process with command `npm start`
2018-02-2...+00:00 app[web.1]:
2018-02-2...+00:00 app[web.1]: > parse-server-example#1.4.0 start /app
2018-02-2...+00:00 app[web.1]: > node index.js
2018-02-2...+00:00 app[web.1]:
2018-02-2...+00:00 app[web.1]: parse-server-example running on port 23377.
2018-02-2...+00:00 heroku[web.1]: State changed from starting to up
2018-02-2...+00:00 heroku[router]: at=info method=GET path="/health" host=myapp.herokuapp.com request_id=fb429287-9b14-4373-97ab-30dac19a4db7 fwd="1.2.3.438" dyno=web.1 connect=2ms service=20ms status=404 bytes=217 protocol=https
2018-02-28T04:03:21.595649+00:00 app[web.1]:
2018-02-28T04:03:21.595660+00:00 app[web.1]: WARNING, Unable to connect to 'https://myapp.herokuapp.com/'. Cloud code and push notifications may be unavailable!
2018-02-28T04:03:21.595663+00:00 app[web.1]:
And if I change https to http in my configuration, I see exactly the same behavior.
Beside if I try to access to https://myapp.herokuapp.com/ in a browser I can do it with no problem.
I have read many post on the issue but nothing drove me to a solution.
That would be great if someone could let me know how to solve this.
I faced this issue and it might help someone in the future.
Note that this is one of the reasons why this warning might be thrown.
This is for parse server version: 2.8.2
To create your own standalone parse server, using express, the basic steps involved are close to:
Create a parse-server object with all your config like. For example: const api = new ParseServer(config);
config will contain the server URL along with all other requirements.
Create an express app object. For example: const app = express();
Then mount the parse server API on the express like -> app.use(mountPath, api);
And then create the server like: const httpServer = require('http').createServer(app);
And then start listening on a port like: httpServer.listen(port);
As soon as the mount is called, the parse-server will verify the url mentioned in the config by making a request to /health endpoint.
If for some reason there is a delay in listening to the port (point 6) after mounting the API (point 4), then the above warning will be thrown.
For example, in one case I was establishing a mongoose connection and only then started listening to the port. Because of this, the verification of URL from parse server failed, although everything worked fine after that.
And one of the possible solutions is to get done with all such work before mounting the parse API and ensuring no delay between mounting and listening to the port as described above.
While this may not be the exact steps for creating a parse server on heroku, the idea is that:
parse server will call verify url on the server url mentioned in the configs.
And if there is delay in starting the server after you have mouted the parse apis, the above warning will be thrown.
2018-02-2...+00:00 heroku[router]: at=info method=GET path="/health" host=myapp.herokuapp.com request_id=fb429287-9b14-4373-97ab-30dac19a4db7 fwd="1.2.3.438" dyno=web.1 connect=2ms service=20ms status=404 bytes=217 protocol=https
Notice status is 404, this doesn't exist, and the host says myapp.herokuapp.com
Do you perhaps have a server_url key set to literally myapp.heroku.com, or did you redact the name of your app?
I'm trying to get mern app working on heroku. But right now even fixing of node server would be enough.
This is what i have already done.
Created app in heroku and push my project to it.
Added mLab database link. (running properly on local server)
put dev dependencies on the dependencies.
Tried running "heroku run node server.js" through heroku CLI. Then it logs as server started on port 8080.
But I cannot access the API or the web interface.
My app url = http://travelaround.herokuapp.com
Please note my web application was create using create-react-app
My Logs at heroku,
2017-05-14T17:17:50.113754+00:00 heroku[api.1]: Process exited with status 0
2017-05-14T17:17:52.979224+00:00 heroku[api.1]: Starting process with command `nodemon server.js`
2017-05-14T17:17:53.538796+00:00 heroku[api.1]: State changed from starting to up
2017-05-14T17:17:55.154398+00:00 app[api.1]: [33m[nodemon] 1.11.0[39m
2017-05-14T17:17:55.156364+00:00 app[api.1]: [33m[nodemon] to restart at any time, enter `rs`[39m
2017-05-14T17:17:55.156522+00:00 app[api.1]: [33m[nodemon] watching: *.*[39m
2017-05-14T17:17:55.157062+00:00 app[api.1]: [32m[nodemon] starting `node server.js`[39m
2017-05-14T17:17:55.982045+00:00 app[api.1]: Database connection Established at mongodb://test:asd123#ds139791.mlab.com:39791/travelaround
2017-05-14T17:17:56.008148+00:00 app[api.1]: api running on port 3000
2017-05-15T14:22:19.692618+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=travelaround.herokuapp.com request_id=b46a031e-db9d-4cac-93fa-ffd73f51e5f3 fwd="93.65.70.107" dyno= connect= service= status=503 bytes= protocol=http
2017-05-15T14:22:20.297803+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=travelaround.herokuapp.com request_id=9ca4977c-b45e-4f3e-b98a-1034855e8c4f fwd="93.65.70.107" dyno= connect= service= status=503 bytes= protocol=http
Ok, so from the screenshot of your Heroku dashboard and error, it looks like your dynos are not running. I suggest you compile all of your react code, so you only have static content on your frontend, and then turn on the API dyno, so you can actually curl to it from your react code.
It is the first time I do something like this. Any pointers or tips to the right direction will greatly help.
I am trying to run this Bitgo's service on Heroku. I followed Heroku's tutorial and pushed the app.
This app is not a web app. It is a service receiving requests. I am wondering how I will run it to receive this requests on Heroku.
I created a "Procfile" and wrote the following line in it:
web: ./bin/bitgo-express
Then when I check the logs (without doing or trying anything at all) I get the following errors and logs:
2016-06-16T08:22:35.353721+00:00 heroku[web.1]: State changed from crashed to starting
2016-06-16T08:22:37.366281+00:00 heroku[web.1]: Starting process with command `./bin/bitgo-express`
2016-06-16T08:22:40.433443+00:00 app[web.1]: BitGo-Express running
2016-06-16T08:22:40.434385+00:00 app[web.1]: Environment: test
2016-06-16T08:22:40.434540+00:00 app[web.1]: Base URI: http://localhost:3080
2016-06-16T08:23:37.991458+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-06-16T08:23:37.991458+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-06-16T08:23:38.795553+00:00 heroku[web.1]: Process exited with status 137
2016-06-16T08:23:38.810670+00:00 heroku[web.1]: State changed from starting to crashed
2016-06-16T08:23:41.439218+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=example.com request_id=a42a1654-2593-499c-81fa-a585464b2805 fwd="109.110.240.32" dyno= connect= service= status=503 bytes=
2016-06-16T08:23:42.964194+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=example.com request_id=008620c3-b40f-43c1-add3-e3f8b785d5c5 fwd="109.110.240.32" dyno= connect= service= status=503 bytes=
A note. When I run this service locally it opens a website that redirects to a bitgo's website but I am also able to execute commands and work with the service.
I googled the error and tried this solution which proposes to change the listening port but I was still getting the same behaviour. Just to clarify on the bitgo app I changed all 3080 ports to 5000 that Heroku uses.
I then tried this solution which proposes to change the "web" process to "worker" but I was getting errors that they seem to be generated because of the reason that the service was not structured as a worker process (maybe, that is what I think) but web process.
And lastly, I changed the procfile's text to web: ./bin/bitgo-express -p 3080 so it runs at the 3080 port but I was still getting the same error
Edit:
I have web: ./bin/bitgo-express -p 5000 -b 0.0.0.0 in my procfile.
Again, same result. Here are the logs:
2016-06-20T06:17:36.753762+00:00 heroku[web.1]: Starting process with command `./bin/bitgo-express -p 5000 -b 0.0.0.0`
2016-06-20T06:17:39.333304+00:00 app[web.1]: BitGo-Express running
2016-06-20T06:17:39.334368+00:00 app[web.1]: Environment: test
2016-06-20T06:17:39.334384+00:00 app[web.1]: Base URI: http://0.0.0.0:5000
2016-06-20T06:18:36.768622+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-06-20T06:18:36.768550+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Make sure you specify -b or --bind as 0.0.0.0 in your Profile. Otherwise, it will try to bind to localhost, which cannot be reached from Heroku's routing tier.
You should use the $PORT environment variable provided by Heroku on your Procfile, i.e rails application: web: bin/rails server -p $PORT -e $RAILS_ENV
For BitGo you can configure like that: web: ./bin/bitgo-express -p $PORT -b 0.0.0.0