Made Dockerfile for FE, serve.js for express server, and docker-compose to run both FE and BE services

This commit was merged in pull request #15.
This commit is contained in:
2023-03-18 15:46:07 -04:00
parent 9b0b7b0ec7
commit cef00dac0e
3 changed files with 62 additions and 0 deletions

14
docker-compose.yml Normal file
View File

@@ -0,0 +1,14 @@
version: '3'
services:
frontend:
image: comp2707-frontend
build: frontend/
container_name: comp2707-frontend
ports:
- 8080:8080
backend:
image: comp2707-backend
build: backend/
container_name: comp2707-backend
ports:
- 5000:5000

15
frontend/Dockerfile Normal file
View File

@@ -0,0 +1,15 @@
FROM node:18.3.0-alpine AS builder
# Install all node dependencies separately so it's cached in docker build
COPY ./package.json /tmp/package.json
RUN cd /tmp && npm install
RUN mkdir /code && cp -a /tmp/node_modules /code/
# Copy all the source code
WORKDIR /code
COPY ./ /code
# Build the project
RUN ["npm", "run", "build"]
CMD ["node", "serve.js"]

33
frontend/serve.js Normal file
View File

@@ -0,0 +1,33 @@
const express = require("express");
const path = require("path");
const app = express();
app.use("/*", (req, res, next) => {
now = new Date();
var datetime =
now.getFullYear() +
"/" +
(now.getMonth() + 1) +
"/" +
now.getDate() +
" " +
now.getHours() +
":" +
now.getMinutes() +
":" +
now.getSeconds();
console.log(datetime, req.method, req.baseUrl);
res.setHeader("X-Powered-By", "Ligma"); // Hide server to the client
next();
});
app.use(express.static(path.join(__dirname, "build")));
app.get("/*", function (_, res) {
res.sendFile(path.join(__dirname, "build", "index.html"));
});
app.listen(8080, () => {
console.log("Server started on port 8080");
});