S
S
Stepan2021-04-04 14:42:41
Express.js
Stepan, 2021-04-04 14:42:41

How to listen on port 443 via express?

I use cloudflare for https. I generated cert.pem and key.pem for the domain. I threw everything into a small program:

var fs = require('fs');
var https = require('https');
var privateKey  = fs.readFileSync('./key.pem', 'utf8');
var certificate = fs.readFileSync('./cert.pem', 'utf8');

var credentials = {key: privateKey, cert: certificate};
var express = require('express');
var app = express();

var httpsServer = https.createServer(credentials, app);
app.get('/', (req, res) => {
    res.send({ message: 'Hello WWW!' });
});

httpsServer.listen(8443);


Through port 8443, everything listens perfectly. When you request https://domen.ru:8443/ , the words Hello WWW! But it’s not very nice to contact through the port, so I would like to access it through https://domen.ru
I tried to wiretap port 443, the application started, and an error from cloudflare appeared on the page:
Error 521
Web server is down

How then to accept requests through a regular URL https://domen.ru without a port?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2021-04-04
@Stepashka20

Install Nginx, in addition to the simplest Certificate Settings, you will also cache statics.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question