From 3914735337d2d83ae5457e9ba209d7031e63f5f0 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Fri, 20 Nov 2020 12:36:37 +0100 Subject: [PATCH] Add ssl --- .gitignore | 3 ++- client/Dockerfile | 2 +- client/app.js | 10 +++++++++- client/package.json | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 88b20a4..31814c3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ node_modules/ dist/ .env .vscode/ -mongodb-binaries/ \ No newline at end of file +mongodb-binaries/ +certs/ \ No newline at end of file diff --git a/client/Dockerfile b/client/Dockerfile index 9eaed58..517b9fd 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -9,4 +9,4 @@ RUN npm ci COPY . . EXPOSE 80 -CMD [ "node", "app.js" ] \ No newline at end of file +CMD [ "npm", "start" ] \ No newline at end of file diff --git a/client/app.js b/client/app.js index c9a513b..6a9d8b4 100644 --- a/client/app.js +++ b/client/app.js @@ -1,5 +1,6 @@ const express = require("express"); const jwt = require("jsonwebtoken"); +const fs = require("fs"); const app = express(); @@ -7,7 +8,6 @@ require("dotenv").config(); app.set("views", __dirname + "/views"); app.set("view engine", "jsx"); -app.use("/", express.static(__dirname + "/public")); app.engine( "jsx", require("express-react-views").createEngine({ @@ -47,3 +47,11 @@ app.get("/*", (req, res) => { }); app.listen(process.env.PORT || 80); + +if (process.env.NODE_ENV === "production") { + const options = { + cert: fs.readFileSync("./certs/fullchain.pem"), + key: fs.readFileSync("./certs/privkey.pem"), + }; + https.createServer(options, app).listen(8443); +} diff --git a/client/package.json b/client/package.json index ec32167..b07846a 100644 --- a/client/package.json +++ b/client/package.json @@ -4,7 +4,7 @@ "description": "React Parcel Boilerplate", "main": "index.js", "scripts": { - "start": "node app.js", + "start": "NODE_ENV=production node app.js", "start:dev": "nodemon app.js", "build": "sh ./build.sh", "test": "jest --coverage"