Compare commits

...

7 Commits

Author SHA1 Message Date
Notoric b75dce5352 Added mongo container 2024-08-05 18:32:46 +01:00
Wilkozx 3ab0e1fa43 Update comment 2024-08-04 18:53:43 +01:00
Wilkozx 822d9100db removed redundant port from env 2024-08-04 18:50:39 +01:00
Wilkozx e2736d1c10 containerized project 2024-08-04 18:49:28 +01:00
Wilkozx 184ec7196d Relocated logging middleware 2024-08-04 18:23:21 +01:00
Wilkozx f9c7359fd6 relocated routes to routes folder 2024-08-04 18:13:02 +01:00
Wilkozx 0cad380e49 setup backend 2024-08-04 18:02:22 +01:00
9 changed files with 114 additions and 2 deletions

5
.gitignore vendored
View File

@ -9,4 +9,7 @@ backend/node_modules/
backend/.env
# Frontend-specific
frontend/node_modules/
frontend/node_modules/
# Database-specific
database/data/

13
backend/Dockerfile Normal file
View File

@ -0,0 +1,13 @@
FROM node:14.15.4
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
EXPOSE 5000
CMD ["node", "index.js"]

18
backend/index.js Normal file
View File

@ -0,0 +1,18 @@
const express = require('express');
// Invoke express app
const app = express();
const APIRoutes = require('./routes/api');
const Loggerware = require('./middleware/Logger');
// Set up middleware
app.use(Loggerware);
// Set up API routes
app.use(APIRoutes);
// Listen on port 5000
app.listen(5000, () => {
console.log('Server is listening on port 5000');
});

View File

@ -0,0 +1,11 @@
const express = require('express');
const Loggerware = express.Router();
Loggerware.use((req, res, next) => {
let time = new Date().toLocaleTimeString();
console.log(time + ' | Request received | path: ' + req.path + ' | method: ' + req.method);
next();
});
module.exports = Loggerware;

View File

@ -9,6 +9,7 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"dotenv": "^16.4.5",
"express": "^4.19.2",
"mongoose": "^8.5.2",
"socket.io": "^4.7.5"
@ -228,6 +229,17 @@
"npm": "1.2.8000 || >= 1.4.16"
}
},
"node_modules/dotenv": {
"version": "16.4.5",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
"integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",

View File

@ -3,13 +3,15 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"dotenv": "^16.4.5",
"express": "^4.19.2",
"mongoose": "^8.5.2",
"socket.io": "^4.7.5"

9
backend/routes/api.js Normal file
View File

@ -0,0 +1,9 @@
const express = require('express');
const APIRoutes = express.Router();
APIRoutes.get('/', (req, res) => {
res.json({'message': 'Hello World!'});
});
module.exports = APIRoutes;

31
docker-compose.yml Normal file
View File

@ -0,0 +1,31 @@
services:
backend:
container_name: backend
build:
context: ./backend
dockerfile: Dockerfile
working_dir: /app
ports:
- "5000:5000"
volumes:
- ./backend:/app
frontend:
container_name: frontend
build:
context: ./frontend
dockerfile: Dockerfile
ports:
- "3000:3000"
volumes:
- ./frontend:/app
- ./frontend:/node_modules
db:
container_name: database
image: mongodb/mongodb-community-server
ports:
- "27017:27017"
volumes:
- ./database/data:/data/db

13
frontend/Dockerfile Normal file
View File

@ -0,0 +1,13 @@
FROM node:14.15.4
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]