I have created an ExpressJS-server that provides a route for a get request.
I am using a self-signed certificate to allow https calls. It works perfectly when I perform the request via the major browsers (chrome, safari and firefox). However, when it comes to the real usage case, namely do a get-request via another nodeJs-script, the server fails to pass the request and I get this error message:
Error: unable to verify the first certificate
at TLSSocket.<anonymous> (_tls_wrap.js:1105:38)
at emitNone (events.js:106:13)
at TLSSocket.emit (events.js:208:7)
at TLSSocket._finishInit (_tls_wrap.js:639:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:469:38)
My Express app-configuration:
app.use([
express.urlencoded({ extended: true }),
express.json(),
function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Methods", "GET");
next();
},
]);
The sever is created using the node https package:
const credentials = {
key: fs.readFileSync(credits.sslPrivateKey, "utf8"),
cert: fs.readFileSync(credits.sslCertificate, "utf8")
};
let httpsServer = https.createServer(credentials, app);
The corresponding packges:
express: "^4.16.3",
node: v8.10.0,
npm: 5.8.0