I'm running into this major issue on my Heroku app: I have an Express route set up
as follows:
app.get('/recommendations/:data', (req, res) => {
let dataSplit = req.params.data.split("");
let dataInt = [];
dataSplit.forEach(char => dataInt.push(parseInt(char)));
function sendPrediction(dataInf) {
const process = spawn('python', ["./predict.py", dataInt]);
process.stdout.on('data', (data) => {
let jSonned = JSON.stringify(data.toString('utf-8'));
let chopped = jSonned.slice(1, jSonned.length - 3);
res.send(chopped.split(','));
});
}
sendPrediction(dataInt);
});
When I make the GET request to this route from the frontend component, it times out with an H12 error after 30 seconds as per Heroku's default behavior. Since this route works fine on my localhost, it leads me to believe that there is something wrong with the Python dependencies, as I can replicate the same behavior on localhost by deactivating my virtualenv. I know this isn't much to go by, but if anyone has seen something like this and can help I'd greatly appreciate it.
How can I figure out where the issue is?
Here is the error from Heroku logs:
2018-04-30T17:17:27.175201+00:00 heroku[router]: at=error code=H12
desc="Request timeout" method=GET path="/recommendations/41231" host=what-
doxd.herokuapp.com request_id=2249d6ac-a389-40c1-8f64-8947796494a7
fwd="12.23.56.98" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0
protocol=https
Issue resolved: I needed to specify Python 2 and not let heroku default to python 3
First of all, you should attach your heroku logs to the question, so that we can see what Heroku is complaining about.
In absence of Heroku logs, I am guessing that you might not have a python buildpack defined for your app. Since your web dyno is built with node/express, you presumably already have a node.js buildpack (which Heroku may have added to your app automatically for you, if you didn't add it explicitly).
In that case, you need to add a python buildpack. Otherwise, python is not included in your app's slug.
See here for instructions on adding another buildpack to your app.
Related
I developed an api with nodejs, express and run (npm start) with pm2 (link). I published the app on heroku in a pipeline, I use the staging and production pipeline. The staging app works fine, but the production app is very inconsistent, succeeding sometimes and failing most.
Below the api access log, in the second request there is an error 404 with "no such app" in the html body error message (it is not in the image log).
2021-11-22T12:52:37.266486+00:00 app[web.1]: Starting server in port 12080
2021-11-22T12:52:37.567394+00:00 heroku[router]: at=info method=POST path="/token" host={hidden}-production.herokuapp.com request_id={hidden} fwd="{hidden}" dyno=web.1ect=0ms service=692ms status=200 bytes=613 protocol=https
2021-11-22T12:53:12.688593+00:00 heroku[router]: at=info method=POST path="/token" host={hidden}-production.herokuapp.com request_id={hidden} fwd="{hidden}" dyno=web.1 connect=0ms service=35ms status=404 bytes=711 protocol=https
I believe it is not a route problem, it works sometimes and in staging it works fine. I'm using Heroku's promotion button (staging -> production).
Is there a problem with Heroku?
Are any different configurations required for the application in production?
The problem was in my app syncing with the Heroku routers.
Was fixed by the Heroku team itself.
I made a simple financial app consisting of a React frontend and Node/express backend that I want to deploy to Heroku. Since it's a small app I put everything (server as well as client files) in the root directory of my git repository. Thus the entry files for frontend (index.html), backend (index.js) and the Procfile required by Heroku are all in the root directory.
The server seems to be working fine, since I can successfully make requests from the locally installed frontend. However it appears that the server cannot serve the static files.
This is the log message from heroku:
2021-07-29T15:21:00.260957+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=xpensoft.herokuapp.com request_id=2a484f4d-30cf-49b9-920d-14b9e9be28fb fwd="31.151.16.151" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https
I am serving the static files using this server code:
if (process.env.NODE_ENV === 'production') {
app.use(express.static(__dirname));
}
Anyone has any idea what could be causing the timeout?
EDIT:
Apart from the code above, which is supposed to serve up the static files (which is unfortunately doesn't) there is no specific code in the server file handling the '/' endpoint. There is only code for specific named endpoints.
In the React app I am redirecting the user using React Router:
<Route exact path='/'>
<Redirect to='/user' />
</Route>
However the React app is never loaded.
request timeout error comes when your app takes more than 30 seconds to send a response back to the client.
So there is some issue with your code which handles the '/' route.
if Your static files are facing issues to get served up, it's most probably the issues with .env file. So manually add the enviorment variables in Heroku Settings > Config Vars
I have a Node.js app running a React front-end hosted on Heroku which is linked to a Github repository so that on push it redeploys the app. I have been using the app this way without problem for around a year now.
It works on Heroku Local, and running the node app locally without Heroku but I'm getting a 503 service unavailable error when I run a put request when running the app online.
2021-06-01T08:04:27.326913+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=PUT path="/api/auth/login" host=myapp.herokuapp.com request_id=9b84f5c5-def4-4dce-82d2-baf1bef3a9a8 fwd="90.215.204.78" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https
Any pointers?
It was fixed by adding a Procfile with: "web:server/index.js" as well as specifying the Node version specifically changing the code in my package.json from:
"engine":"12.x",
to:
"engines": {
"node":"v12.18.3"
},
I think it is likely the package.json change that ultimately fixed the problem.
I know this question has been answered a lot, but I still can't figure out a solution to my problem. I've created a little app which is supposed to work with the Slack webhook. Locally, it works just fine - I use node app in order to launch it.
I've created my app on Heroku, pushed my files (Procfile app.js hellobot.js package.json)
But when I visit http://slackbot2.herokuapp.com/, I get an Application Error message.
I already tried the log but I get this :
2015-06-11T23:39:05.967607+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=slackbot2.herokuapp.com request_id=b3783c70-306b-4528-9d81-4e8ab43e9132 fwd="*******" dyno= connect= service= status=503 bytes=
This heroku run rails console and heroku run rake db:migrate won't work. bash: rails command not found. Rails and Rake are installed on my Mac (OSX 10.10.4). Those were the only solutions that worked for others .. But not me.
Same thing happened with me. As far as I can remember, the reason for this is the port you used in the application. Heroku will not run your app on port 8080 or 3000, instead it will be some random port. Use this code to fix the problem.
var port = process.env.PORT || 8080;
Use this code to start the server.
app.listen(port, function() {
console.log('Our app is running on http://localhost:' + port);
});
This may be a stupid question, but I'm wondering what platform I should use to deploy my Angular.js app? I tried using Heroku but got a "no Cedar-supported app detected" error. Any thoughts?
UPDATE
I'm trying to serve this to heorku as a Node.js application, but still can't seem to get it working. There's a web-server.js file in the root directory of my application and I reference it in my Procfile here:
web: node web-server.js
And here's my package.json file, also in the root directory:
{
"name": "medicare-data",
"version": "0.0.1",
"dependencies": {
},
"engines": {
"node": "0.10.x",
"npm": "1.2.x"
},
"respository": "medicare-data",
"author": "sararob"
}
I'm getting a "slug compilation error" in my heroku logs. Thoughts on why this might not be working?
You can run an Angular app on heroku if it is served as a node.js application. Usually, when you start working with Angular seed, there is already a node webserver script in the project. I believe if there is a package.json file in the root, heroku will detect and run it as a node.js application. I'll come back and update this answer with more detail shortly.
UPDATE
From the Heroku docs (and I am no expert), it has this passage after the deploy section: https://devcenter.heroku.com/articles/nodejs#visit-your-application
which basically tells you to make sure you have one dyno running. You can do that either through the web app under the settings of your app or you can run this:
$ heroku ps:scale web=1
To see if the process is running, do
$ heroku ps
=== web: `node web.js`
web.1: up for 10s
I bet if you look at your logs you'll see something like this:
2013-08-26T12:51:18.257006+00:00 heroku[web.1]: Starting process with command `node scripts/web-server.js`
2013-08-26T12:51:19.109974+00:00 app[web.1]: Http Server running at http://localhost:8000/
2013-08-26T12:51:34.369092+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path=/ host=cmwidget.herokuapp.com fwd="77.101.66.230" dyno= connect= service= status=503 bytes=
2013-08-26T12:52:19.445974+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
It means that your Angular seed app is using it's own port (8000), and Heroku doesn't allow this. You need to relinquish the assignment of the port number to Heroku.
Easily fixed. Modify scripts/web-server.js, and change this:
this.server.listen(port);
...to this:
this.server.listen(process.env.PORT || port);
I changed this line
var DEFAULT_PORT = 8000;
into:
var DEFAULT_PORT = process.env.PORT || 8000;
..and then it worked.
So I believe the reason is that heroku doesn't like your app running on port 8000.