What I used to generate the key/cert:
openssl req -new -x509 -key localhost.key -out localhost.cert -days 3650 -subj /CN=localhost
server.js:
const app = require("./app");
const PORT = process.env.PORT || 5000;
const https = require("https");
const fs = require("fs");
const httpsServer = https.createServer(
{
key: fs.readFileSync("./localhost.key", "utf8"),
cert: fs.readFileSync("./localhost.cert", "utf8"),
requestCert: false,
rejectUnauthorized: false,
},
app
);
httpsServer.listen(PORT, () => console.log(`Listening on port ${PORT}...`));
I've already added the cert into my Keychain Access (option: System
), and set it to Always Trust
.
When I reload the server and page, though, it returns me an error:
NET::ERR_CERT_COMMON_NAME_INVALID
What can I do to successfully run my localhost Express app on https?