I'm just trying to do a simple ssl configuration. I've done it many times before. But now I'm getting a awkward error. The SSL certificate is a letsencrypt certificate.
Here is the index.js file
const express = require("express");
const server = express();
const fs = require("fs");
const mongoose = require("mongoose");
const http = require("http");
const https = require("https");
const posts = require("./routes/posts");
mongoose
.connect(process.env.DATABASE_URI)
.then(() => console.log("connected mongodb"))
.catch(() => console.log("connection error"));
server.use(express.static("public"));
server.use(express.json());
server.use(express.urlencoded({ extended: true }));
server.use(cors());
const privateKey = fs.readFileSync(
"/etc/letsencrypt/live/domain.com/privkey.pem",
"utf8"
);
const certificate = fs.readFileSync(
"/etc/letsencrypt/live/domain.com/cert.pem",
"utf8"
);
const ca = fs.readFileSync(
"/etc/letsencrypt/live/domain.com/chain.pem",
"utf8"
);
const credentials = {
privateKey,
certificate,
ca,
};
http.createServer(server).listen(80);
https.createServer(credentials,server).listen(443)
server.use("/api/posts", posts);
Http server is successfully responding to requests. But there is an error in https server.
It is here;
