How do I use http2 with Node on Heroku (using Koa) - node.js

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.

Related

Node Express server works in Heroku staging pipeline but not on production pipeline (no such app error)

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.

Heroku App rollback works but identical code does not - works perfectly locally

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.

Heroku error code H13 when trying to open app

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

heroku 503ing Asynch API calls on my React App

I am so close to finishing up a project - the coding of it was simple enough, but deployment has been a nightmare. I've got it mostly deployed, but now the app is timing out on API calls, even though they work fine on my localhost server.
Here is the github:
https://github.com/lotg515/portfolio
here is the Heroku deployment:
https://derek-smith-portfolio.herokuapp.com/
and here is the error I'm getting:
at=error code=H12 desc="Request timeout" method=GET path="/api/retrieve/skills" host=derek-smith-portfolio.herokuapp.com request_id=d1f5c23e-4fd1-4348-a1e7-dffbd72bb47b fwd="47.24.173.21" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0 protocol=https
Any clue what might be causing this? I can't seem to figure it out, it works just fine locally, and the API calls i've seen on postman are all under 500ms. What am I doing wrong?
fixed, I had initially kept my mongo_uri variable in quotes in heroku's environmental vars. removing the quotes fixed the issue.

Application Error on new Heroku app

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);
});

Resources