From e98c6474f097ee686a7717952b637416db82b87c Mon Sep 17 00:00:00 2001 From: "theis.gaedigk" Date: Thu, 24 Jul 2025 19:43:10 +0200 Subject: [PATCH] feat: update server URL and enhance Docker configuration with user frontends --- backend/server.js | 2 +- docker-compose.yml | 61 ++++++++++++++++--------- frontend_admin/.env | 2 +- frontend_admin/src/utils/userHandler.ts | 10 ++-- scheme.sql | 47 ++++++++++++++++++- 5 files changed, 91 insertions(+), 31 deletions(-) diff --git a/backend/server.js b/backend/server.js index f1aed34..7fd3602 100644 --- a/backend/server.js +++ b/backend/server.js @@ -118,7 +118,7 @@ app.post("/api/updateUser", authenticate, async (req, res) => { }); app.listen(port, () => { - console.log(`Express backend server is running at http://localhost:${port}`); + console.log(`Express backend server is running at http://45.133.75.67:5002:${port}`); }); // error handling code diff --git a/docker-compose.yml b/docker-compose.yml index 7ca00a4..3c459c9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,33 +1,42 @@ services: - # admin_react-frontend: - # container_name: bikelane-frontend_react-admin - # build: ./frontend_admin - # ports: - # - "5001:5001" - # environment: - # - CHOKIDAR_USEPOLLING=true - # volumes: - # - ./frontend_admin:/app - # - /app/node_modules - # restart: unless-stopped + admin_react-frontend: + container_name: bikelane-frontend_react-admin + build: ./frontend_admin + ports: + - "5001:5001" + networks: + - proxynet + - bikelane_network + environment: + - CHOKIDAR_USEPOLLING=true + volumes: + - ./frontend_admin:/app + - /app/node_modules + restart: unless-stopped - # user_react-frontend: - # container_name: bikelane-frontend_react-user - # build: ./frontend_user - # ports: - # - "5003:5003" - # environment: - # - CHOKIDAR_USEPOLLING=true - # volumes: - # - ./frontend_user:/app - # - /app/node_modules - # restart: unless-stopped + user_react-frontend: + container_name: bikelane-frontend_react-user + build: ./frontend_user + networks: + - proxynet + - bikelane_network + ports: + - "5003:5003" + environment: + - CHOKIDAR_USEPOLLING=true + volumes: + - ./frontend_user:/app + - /app/node_modules + restart: unless-stopped bikelane-backend: container_name: bikelane-backend_express build: ./backend ports: - "5002:5002" + networks: + - proxynet + - bikelane_network environment: DB_HOST: mysql DB_USER: root @@ -43,6 +52,8 @@ services: container_name: bikelane-mysql image: mysql:8.0 restart: unless-stopped + networks: + - bikelane_network environment: MYSQL_ROOT_PASSWORD: D7Ze0lwV9hMrNQHdz1Q8yi0MIQuOO8 MYSQL_DATABASE: bikelane @@ -53,3 +64,9 @@ services: volumes: mysql-data: + +networks: + proxynet: + external: true + bikelane_network: + external: false diff --git a/frontend_admin/.env b/frontend_admin/.env index 332d920..e16c835 100644 --- a/frontend_admin/.env +++ b/frontend_admin/.env @@ -1 +1 @@ -REACT_APP_SERVER_URL=http://localhost:5002 \ No newline at end of file +REACT_APP_SERVER_URL=http://45.133.75.67/ \ No newline at end of file diff --git a/frontend_admin/src/utils/userHandler.ts b/frontend_admin/src/utils/userHandler.ts index 860cde2..d31e2f9 100644 --- a/frontend_admin/src/utils/userHandler.ts +++ b/frontend_admin/src/utils/userHandler.ts @@ -2,7 +2,7 @@ import Cookies from "js-cookie"; import { myToast } from "./frontendService"; export const loginUser = (username: string, password: string) => { - fetch(`http://localhost:5002/api/login`, { + fetch(`http://45.133.75.67:5002/api/login`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username, password }), @@ -12,7 +12,7 @@ export const loginUser = (username: string, password: string) => { const data = await response.json(); Cookies.set("token", data.token, { expires: 7 }); Cookies.set("name", data.user.first_name, { expires: 7 }); - await fetch("http://localhost:5002/api/getAllUsers", { + await fetch("http://45.133.75.67:5002/api/getAllUsers", { method: "GET", headers: { Authorization: `Bearer ${Cookies.get("token")}`, @@ -42,7 +42,7 @@ export const logout = () => { }; export const deleteUser = (id: number) => { - fetch("http://localhost:5002/api/deleteUser", { + fetch("http://45.133.75.67:5002/api/deleteUser", { method: "POST", body: JSON.stringify({ id: id }), headers: { @@ -64,7 +64,7 @@ export const deleteUser = (id: number) => { export const replaceUsers = async (alertMessage: string) => { localStorage.removeItem("users"); - await fetch("http://localhost:5002/api/getAllUsers", { + await fetch("http://45.133.75.67:5002/api/getAllUsers", { method: "GET", headers: { Authorization: `Bearer ${Cookies.get("token")}`, @@ -115,7 +115,7 @@ export const updateUserFunc = async (userID: number) => { console.log("Sending user data:", userData); try { - const response = await fetch("http://localhost:5002/api/updateUser", { + const response = await fetch("http://45.133.75.67:5002/api/updateUser", { method: "POST", body: JSON.stringify(userData), headers: { diff --git a/scheme.sql b/scheme.sql index e4b1341..746b846 100644 --- a/scheme.sql +++ b/scheme.sql @@ -11,8 +11,51 @@ CREATE TABLE users ( ); -- Mock data for users +INSERT INTO users (username, first_name, last_name, email, password, role) +VALUES +('t', 'John', 'Doe', 'd@example.com', 'g', 'admin'); + INSERT INTO users (username, first_name, last_name, email, password) VALUES ('test1', 'John', 'Doe', 'jdoe@example.com', '1test'), -('t', 'John', 'Doe', 'd@example.com', 'g'), -('test2', 'Alice', 'Smith', 'asmith@example.com', '2test'); \ No newline at end of file +('test2', 'Alice', 'Smith', 'asmith@example.com', '2test'), +('test3', 'Bob', 'Johnson', 'bjohnson@example.com', '3test'), +('test4', 'Carol', 'Williams', 'cwilliams@example.com', '4test'), +('test5', 'David', 'Brown', 'dbrown@example.com', '5test'), +('test6', 'Eve', 'Davis', 'edavis@example.com', '6test'), +('test7', 'Frank', 'Miller', 'fmiller@example.com', '7test'), +('test8', 'Grace', 'Wilson', 'gwilson@example.com', '8test'), +('test9', 'Hank', 'Moore', 'hmoore@example.com', '9test'), +('test10', 'Ivy', 'Taylor', 'itaylor@example.com', '10test'), +('test11', 'Jack', 'Anderson', 'janderson@example.com', '11test'), +('test12', 'Kathy', 'Thomas', 'kthomas@example.com', '12test'), +('test13', 'Leo', 'Jackson', 'ljackson@example.com', '13test'), +('test14', 'Mona', 'White', 'mwhite@example.com', '14test'), +('test15', 'Nina', 'Harris', 'nharris@example.com', '15test'), +('test16', 'Oscar', 'Martin', 'omartin@example.com', '16test'), +('test17', 'Paul', 'Thompson', 'pthompson@example.com', '17test'), +('test18', 'Quinn', 'Garcia', 'qgarcia@example.com', '18test'), +('test19', 'Rita', 'Martinez', 'rmartinez@example.com', '19test'), +('test20', 'Sam', 'Robinson', 'srobinson@example.com', '20test'), +('test21', 'Tina', 'Clark', 'tclark@example.com', '21test'), +('test22', 'Uma', 'Rodriguez', 'urodriguez@example.com', '22test'), +('test23', 'Vince', 'Lewis', 'vlewis@example.com', '23test'), +('test24', 'Wendy', 'Lee', 'wlee@example.com', '24test'), +('test25', 'Xander', 'Walker', 'xwalker@example.com', '25test'), +('test26', 'Yara', 'Hall', 'yhall@example.com', '26test'), +('test27', 'Zane', 'Allen', 'zallen@example.com', '27test'), +('test28', 'Amy', 'Young', 'ayoung@example.com', '28test'), +('test29', 'Ben', 'King', 'bking@example.com', '29test'), +('test30', 'Cathy', 'Wright', 'cwright@example.com', '30test'), +('test31', 'Dan', 'Scott', 'dscott@example.com', '31test'), +('test32', 'Ella', 'Green', 'egreen@example.com', '32test'), +('test33', 'Finn', 'Baker', 'fbaker@example.com', '33test'), +('test34', 'Gina', 'Adams', 'gadams@example.com', '34test'), +('test35', 'Hugo', 'Nelson', 'hnelson@example.com', '35test'), +('test36', 'Iris', 'Carter', 'icarter@example.com', '36test'), +('test37', 'Jake', 'Mitchell', 'jmitchell@example.com', '37test'), +('test38', 'Kara', 'Perez', 'kperez@example.com', '38test'), +('test39', 'Liam', 'Roberts', 'lroberts@example.com', '39test'), +('test40', 'Mia', 'Turner', 'mturner@example.com', '40test'), +('test41', 'Noah', 'Phillips', 'nphillips@example.com', '41test'), +('test42', 'Olga', 'Campbell', 'ocampbell@example.com', '42test'); \ No newline at end of file