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
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 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.
hi i am getting a problem while trying to deploy my app on heruko
the following error
and my Procfile looks like
web: npm start
2019-10-25T03:31:44.445209+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=andela-api.herokuapp.com request_id=ee3f68c6-e7a5-4212-8277-bddd8a33027c fwd="41.186.25.0" dyno= connect= service= status=503 bytes= protocol=https```
Favicon file is an image file(usually website logo) that you see on the browser tab. It has extension .ico. Your project cannot find that file.
If you do not have favicon.ico file in your project, then create one and upload it at suitable location(make sure it's accessible via url /favicon.ico).
If you have favicon file in your project, the problem is related to permission to access the file via /favicon.ico (make sure the folder where you have the file stored is public so that it can be access via url /favicon.ico)
How to create favicon file?
Use favicon generator site such this one. Upload your logo file and download the favicon generated by the site.
I had react app and after deploying to heroku I got the same error. The reason of this, I deleted favicon.ico and manifest.json files in public folder. After adding favicon.ico and manifest.json files in public folder, the error solved.
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.
My nodejs app runs fine locally and all resources are available.
When uploaded to heroku it cannot find 4 css/js resources, where as everything else is loading fine locally and on heroku.
I have tried:
Checking the remote heroku directory to make sure the missing files exist within my public/vendor directory - they do.
I tried changing the static path for 'production' but this seems to have no impact.
var env = process.env.NODE_ENV || 'development';
if ('development' == env) {
mongoose.connect(configDB.devurl); // connect to our database
app.use(morgan('dev')); // log every request to the console
app.use(express.static(path.join(__dirname, 'public')));
}
if ('production' == env) {
process.env.PWD = process.cwd();
mongoose.connect(configDB.produrl); // connect to our database
app.use(express.static(process.env.PWD + '/public'));
}
Any ideas? I am well and truly confused. This is what the heroku log shows when I just point directly at the file:
2016-01-03T08:58:05.943206+00:00 heroku[router]: at=info method=GET path="/vendor/metisMenu/dist/metisMenu.css" host=sleepy-refuge-6282.herokuapp.com request_id=47bd858a-8dd6-4fe3-b99c-33d2f135d719 fwd="94.0.192.69" dyno=web.1 connect=1ms service=2381ms status=404 bytes=246
I am using express 4
You are developing your application on OS X or Windows which filesystem isn't case sensitive.
Heroku Dynos are actually linux containers with case sensitive file system, so filename's case should match there.
The answer is that on heroku the files need to have the same case as the underlying folder structure in the app. It doesn't have an impact on my localhost but it does when pushed to Heroku for some reason.