I am using expressjs to create an http/https server.
There was a case wherein the server was not able to fetch the public and private certificate files from a directory.
In which case I create the server using http and send a raw HTML file to the client indicating that there was an issue, but here lies the problem, the user does not know that they need to move to http url rather than https to see the HTML file.
So is there a way I can redirect my users to a https url when they try to access the http URL
init.js
try {
// options = get public and private certificate file
} catch(e) {
// accessError
}
if(accessError) {
server = http.createServer();
} else {
server = https.createServer(options, (req, res) => {
res.writeHead(200);
res.end('hello world\n');
});
);
}
server.listen(8080);
app.js
let app = require('express');
app.use((req, res, next) => {
if(accessError) {
res.sendFile(index.html);
} else {
next();
}
});
index.html
<h1> there was an error <h1>