I'm currently working on deploying a fullstack webapp to DigitalOcean, where I have 2 docker images - One for the frontend to statically serve files, and an ExpressJS backend that handles any logic for API calls. I have recently added CloudFlare to my website, which has enabled HTTPS, and while that is progress, now my backend is no longer responsive from the domain when doing HTTPS, if i access it by going to my droplet's ip(unsecure, HTTP) I can see that my api requests are working, but on the main HTTPS site, the entire backend is unresponsive.
I am currently mapping my frontend to port 80 outside of the docker container (from port 3000 inside) and 3001:3001 for my backend. I've heard that I should maybe use nginx, but I'm unsure how that works with my 2 docker images, and I've tried to use https.createServer(options, app)
to try to get it to listen for the HTTPS requests, but to no avail.
Here is my current backend now:
const express = require("express");
const webserver = express();
const cors = require("cors");
const mysql = require("mysql");
// Connection pool here
webserver.use(cors());
webserver.use(express.json());
const PORT = 3001;
//api routes here
webserver.listen(PORT, () => {
console.log(`[Express] Server running on ${PORT}`);
});
Any step in the right direction would be much appreciated, I've been researching how to fix this for ~10 hours with no luck.
Edit: I believe the solution is not to change the Express server to allow HTTPS, but somehow have Nginx do a reverse proxy and convert it to HTTP before it even hits the Express server, but I am unsure of how this is done.