0

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?

Sabrina
  • 23
  • 4
  • *"__it__ returns me an error:"* - what is "__it__" ? Is this a message you get when starting the server? Is this a message you get in the browser when accessing the server? And in the latter case - what browser and what URL you are using to access the server? – Steffen Ullrich Feb 10 '21 at 04:59
  • The latter. Browser: Chrome (88.0.4324.146), URL: `https://localhost:5000` – Sabrina Feb 10 '21 at 10:25
  • In short: the certificate has no subject alternative name, chrome requires it, i.e. CN is not sufficient. – Steffen Ullrich Feb 10 '21 at 10:31

0 Answers0