0

Having lots of trouble trying to get an Express.JS server going that supports HTTPS requests.

Here is the code I've written thus far:

import express from 'express';
import fs from 'fs';
import https from 'https';

const app = express();
const port = 3000;

const options = {
  cert: fs.readFileSync('server.crt', 'UTF-8'),
  key: fs.readFileSync('server.key', 'UTF-8'),
};

app.get('/', (request, response) => response.send('Success!'));

https.createServer(options, app).listen(port, () => console.log(`Listening on port ${port}`));

I've created the SSL credentials using OpenSSL on macOS as follows:

openssl req -nodes -new -x509 -out server.crt -keyout server.key

I've also tried a few other arguments, including increasing key strength to 2048 bits, but nothing has worked. I'm fairly sure that OpenSSL is not the issue here. Requests made to https://localhost:3000/ fail. I've made the requests through Google Chrome, Node.JS via the request module, as well as cURL.

Chrome error: NET::ERR_CERT_INVALID

Node.JS error: Error: connect ETIMEDOUT 172.0.0.1:3000

cURL error: curl: (7) Failed to connect to 172.0.0.1 port 3000: Operation timed out

I've exhausted Google search, so any help would be greatly appreciated. Thanks.

broment
  • 76
  • 6
  • localhost has IP `127.0.0.1`, not `172.0.0.1`. Also check the answers [here](https://stackoverflow.com/questions/10175812/how-to-create-a-self-signed-certificate-with-openssl) to read about problems withs self-signed certificates. –  Feb 16 '20 at 23:44
  • My bad! Thanks for pointing that out. Still unable to get around the invalid cert error. – broment Feb 16 '20 at 23:47

0 Answers0