Complete setup for frontend #15
14
docker-compose.yml
Normal file
14
docker-compose.yml
Normal 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
15
frontend/Dockerfile
Normal 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
33
frontend/serve.js
Normal 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");
|
||||
});
|
||||
Reference in New Issue
Block a user