jeudi 31 décembre 2020

Heroku crashes while it works on my local server

I'm trying to run a little HTTPS server with Heroku, but it's just giving me this error: at=error code=H13 desc="Connection closed without response" method=GET path="/" host=###.herokuapp.com request_id=### fwd="###" dyno=web.1 connect=0ms service=6ms status=503 bytes=0 protocol=https

My server looks like this:

let https = require("https");
let port = process.env.PORT;
if (port == null || port == "") {
    console.log("Using port 80");
    port = 8000;
} else {
    console.log("Using port supplied by Heroku");
    port = Number(port);
}

console.log(`Listening on port ${port}`);
const options = {
    key: [my key],
    cert: [my cert]
};
 
https.createServer(options, (request, response) => {
    console.log("Request recieved")
    response.writeHead(200);
    response.write("<!DOCTYPE html><head></head><body>hello world</body>")
    response.end();
}).listen(port);

I dont have any problems running it locally with heroku local web. Why does this happen and how can I fix this?

EDIT: Turns out that you have to pay Heroku 25 bucks a month to get HTTPS. See this answer.




Aucun commentaire:

Enregistrer un commentaire