I am using nodejs to handle my server and I have a website on it.
I recently set up SSL and want to redirect http to https but couldn't do it. I tried every approved solution on stackoverflow but none of them are working.
Here is my server app:
const express = require('express');
const app = express();
const https = require('https');
const fetch = require('node-fetch');
const bcrypt = require('bcrypt');
const hogan = require('hogan.js');
const fs = require('fs');
const optionSSL = {
key: fs.readFileSync("./etc/ssl/myssl.pem"),
cert: fs.readFileSync("./etc/ssl/myssl.crt")
};
//app.listen(80, () => console.log("Listening at 80"));
app.use(express.static('public', {
extensions: ['html', 'htm'],
}));
app.use(express.json({limit: '1mb'}));
app.use(express.urlencoded({ extended: false }));
https.createServer(optionSSL, app).listen(443, "mydomain.com");
The things that I tried:
Automatic HTTPS connection/redirect with node.js/express