I tried deploying my node.js app to Heroku which worked ok until i try to connect to it (open the app).
The error is get is as follows:
2021-02-18T00:16:03.975921+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/" host=gtdb.herokuapp.com request_id=16579da6-aa8e-4184-8e1c-7ac9680d0078 fwd="-myipaddresswhichidontwanttoshare-" dyno=web.1 connect=0ms service=1ms status=503 bytes=0 protocol=https
My code:
const express = require("express");
const https = require("https");
app = express();
const options = {
key: fs.readFileSync("./server.key"),
cert: fs.readFileSync("./server.crt")
};
const server = https.createServer(options, app);
server.listen(process.env.PORT);
Of course i searched for the issue and some sites say that it could be a timeout and their errors had connect and service times of up to 30000ms where a timeout would make perfect sense but im far away from 30s so i dont know what the issue is here.
The app does not crash after it throws that error.
Any help is much appreciated. Thanks in advance.
Heroku servers are controlled at their load balancers which terminates SSL and sends the request to your server without SSL.
So you should be using the HTTP server instead of HTTPS on Heroku.
You can use this package https://github.com/paulomcnally/node-heroku-ssl-redirect/ to redirect any incoming HTTP traffic from the client to HTTPS.
https://mishkaorakzai.medium.com/how-to-redirect-your-node-js-app-hosted-on-heroku-from-http-to-https-50ef80130bff
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 express application it use Node-Serialport library . which is deployed in Heroku cloud platform. When it is running on localhost, then it is working perfectly. When I deploy in Heroku platform, then it is not getting the port data.
It is throwing the below error in Heroku logs,
2021-11-03T08:44:28.769675+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/api/v1/port/list" request_id=b1391b01-b640-403f-b0a3-7e389e83bc03 fwd="157.49.66.149" dyno=web.1 connect=0ms service=20ms status=503 bytes=0 protocol=https 2021-11-03T08:44:28.877150+00:00 heroku[web.1]: Process exited with status 1
Can we possible to solve this problem ?
My code snippet,
var express = require('express'),
app = express(),
bodyParser = require('body-parser'),
port = process.env.PORT || 3000,
cors = require('cors');
require("dotenv").config();
const SerialPort = require('serialport');
app.use(bodyParser.json())
app.use(cors({
origin: '*'
}));
const server = require('http').createServer(app);
app.get('/port/list', async (req, res) => {
const list = await SerialPort.list();
return res.send(list);
})
server.listen(port, "0.0.0.0", function () {
console.log("Listening on Port 3000");
});
It is working on my localhost which reads the local machine port datas.
You Can't Do Thatâ„¢.
When you run your nodejs app on Heroku or any other server, the serialport package attempts to access the serial ports on the server, not on your local machine. On the sort of virtual machine deployed by Heroku and many other cloud providers, the physical serial ports simply aren't available to software running on the virtual machine.
And, what would you do with the serial port if you could access it? It's somewhere in a vast rack of servers in some data center.
If you need to access the serial port on a local machine with a web app, you'll need the Web API called Serial. Unfortunately it's only available on Chromium-based browsers.
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 the following code...
const PORT = process.env.PORT || 5000;
const app = new Koa();
...
app.listen(PORT)
This works great both locally and in Heroku. So now I want to use Http2 so I change to the following...
const server = http2.createSecureServer(
{
"key": fs.readFileSync('./server-key.pem'),
"cert": fs.readFileSync('./server-cert.pem')
},
app.callback()
)
server.listen(PORT);
This works ok locally, however, when I upload to Heroku I get...
2021-06-24T00:43:00.383108+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/" host=my-app.herokuapp.com request_id=604f4a2c-8dd2-4cfa-9cf2-3cce5ef76070 fwd="..." dyno=web.1 connect=0ms service=1ms status=503 bytes=0 protocol=https
So how do I get http2 working with Node, Koa, and Heroku?
Per this article on devcenter.heroku.com, Heroku does not yet support http/2.
You can use an add-on like https://elements.heroku.com/addons/expeditedwaf or you can use cloudflare. If you decide to use cloudflare, make sure you add a SSL certificate between cloudflare and heroku.
Alternatively have a look at https://elements.heroku.com/addons/expeditedcdn.
It should be way cheaper than the full blown Web App Firewall.
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);
});