Browse Source

ADD SSL certifcates AND update nginx configuration to handle HTTPS

features/create-channel
Astri4-4 5 months ago
parent
commit
0389189946
  1. 2
      backend/app/routes/user.route.js
  2. BIN
      backend/app/uploads/profiles/astria.png
  3. BIN
      backend/app/uploads/profiles/sacha.jpg
  4. 77
      backend/logs/access.log
  5. 9
      docker-compose.yaml
  6. 15
      nginx/default.conf
  7. 23
      nginx/nginx-selfsigned.crt
  8. 28
      nginx/nginx-selfsigned.key

2
backend/app/routes/user.route.js

@ -38,7 +38,7 @@ router.get("/:id", [addLogger, isTokenValid, User.id, validator], getById)
router.get("/username/:username", [addLogger, isTokenValid, UserRequest.username, validator], getByUsername); router.get("/username/:username", [addLogger, isTokenValid, UserRequest.username, validator], getByUsername);
// UPDATE USER // UPDATE USER
router.put("/:id", [addLogger, isTokenValid, User.id, UserRegister.email, UserRegister.username, UserRegister.password, validator, doUserExists, isOwner], update); router.put("/:id", [addLogger, isTokenValid, User.id, UserRegister.email, UserRegister.username, validator, doUserExists, isOwner], update);
// DELETE USER // DELETE USER
router.delete("/:id", [addLogger, isTokenValid, User.id, validator, doUserExists, isOwner], deleteUser); router.delete("/:id", [addLogger, isTokenValid, User.id, validator, doUserExists, isOwner], deleteUser);

BIN
backend/app/uploads/profiles/astria.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

BIN
backend/app/uploads/profiles/sacha.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

77
backend/logs/access.log

@ -1218,3 +1218,80 @@
[2025-07-20 20:51:37.656] [undefined] GET(/:id/channel): failed due to invalid values with status 400 [2025-07-20 20:51:37.656] [undefined] GET(/:id/channel): failed due to invalid values with status 400
[2025-07-20 20:51:37.660] [undefined] GET(/:id/history): failed due to invalid values with status 400 [2025-07-20 20:51:37.660] [undefined] GET(/:id/history): failed due to invalid values with status 400
[2025-07-20 20:51:37.662] [undefined] GET(/user/:id): failed due to invalid values with status 400 [2025-07-20 20:51:37.662] [undefined] GET(/user/:id): failed due to invalid values with status 400
[2025-07-21 08:25:33.854] [undefined] POST(/): try to register a user with username: sacha and email: test@test.test
[2025-07-21 08:25:33.934] [undefined] POST(/): successfully registered with status 200
[2025-07-21 08:25:33.956] [undefined] POST(/login): try to login with username 'sacha'
[2025-07-21 08:25:34.017] [undefined] POST(/login): Successfully logged in with status 200
[2025-07-21 08:25:43.729] [undefined] GET(/:id/history): try to retrieve history of user 1
[2025-07-21 08:25:43.731] [undefined] GET(/:id/channel): try to retrieve channel of user 1
[2025-07-21 08:25:43.733] [undefined] GET(/:id/history): failed to retrieve history of user 1 because it doesn't exist with status 404
[2025-07-21 08:25:43.735] [undefined] GET(/:id/channel): failed to retrieve channel of user 1 because it doesn't exist with status 404
[2025-07-21 08:25:43.748] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200
[2025-07-21 08:27:05.391] [undefined] GET(/:id/channel): try to retrieve channel of user 1
[2025-07-21 08:27:05.396] [undefined] GET(/:id/history): try to retrieve history of user 1
[2025-07-21 08:27:05.400] [undefined] GET(/:id/channel): failed to retrieve channel of user 1 because it doesn't exist with status 404
[2025-07-21 08:27:05.406] [undefined] GET(/:id/history): failed to retrieve history of user 1 because it doesn't exist with status 404
[2025-07-21 08:27:05.424] [undefined] GET(/user/:id): Playlists retrieved for user with id 1 with status 200
[2025-07-21 13:26:38.560] [undefined] GET(/:id/channel): Invalid token with status 401
[2025-07-21 13:26:38.574] [undefined] GET(/user/:id): Invalid token with status 401
[2025-07-21 13:26:38.578] [undefined] GET(/:id/history): Invalid token with status 401
[2025-07-21 13:26:47.958] [undefined] PUT(/:id): Invalid token with status 401
[2025-07-21 13:27:15.056] [undefined] POST(/): try to register a user with username: astria and email: sachaguerin.sg@gmail.com
[2025-07-21 13:27:15.159] [undefined] POST(/): successfully registered with status 200
[2025-07-21 13:27:15.182] [undefined] POST(/login): try to login with username 'astria'
[2025-07-21 13:27:15.275] [undefined] POST(/login): Successfully logged in with status 200
[2025-07-21 13:27:21.989] [undefined] GET(/:id/history): try to retrieve history of user 2
[2025-07-21 13:27:21.997] [undefined] GET(/:id/channel): try to retrieve channel of user 2
[2025-07-21 13:27:22.001] [undefined] GET(/:id/channel): failed to retrieve channel of user 2 because it doesn't exist with status 404
[2025-07-21 13:27:22.004] [undefined] GET(/:id/history): failed to retrieve history of user 2 because it doesn't exist with status 404
[2025-07-21 13:27:22.023] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200
[2025-07-21 13:31:48.331] [undefined] GET(/:id/channel): try to retrieve channel of user 2
[2025-07-21 13:31:48.335] [undefined] GET(/:id/history): try to retrieve history of user 2
[2025-07-21 13:31:48.347] [undefined] GET(/:id/channel): failed to retrieve channel of user 2 because it doesn't exist with status 404
[2025-07-21 13:31:48.351] [undefined] GET(/:id/history): failed to retrieve history of user 2 because it doesn't exist with status 404
[2025-07-21 13:31:48.367] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200
[2025-07-21 13:43:14.509] [undefined] POST(/login): try to login with username 'astria'
[2025-07-21 13:43:14.642] [undefined] POST(/login): Successfully logged in with status 200
[2025-07-21 13:44:06.419] [undefined] POST(/login): try to login with username 'astria'
[2025-07-21 13:44:06.535] [undefined] POST(/login): Successfully logged in with status 200
[2025-07-21 13:46:40.594] [undefined] GET(/:id/channel): try to retrieve channel of user 2
[2025-07-21 13:46:40.596] [undefined] GET(/:id/history): try to retrieve history of user 2
[2025-07-21 13:46:40.603] [undefined] GET(/:id/channel): failed to retrieve channel of user 2 because it doesn't exist with status 404
[2025-07-21 13:46:40.607] [undefined] GET(/:id/history): failed to retrieve history of user 2 because it doesn't exist with status 404
[2025-07-21 13:46:40.628] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200
[2025-07-21 13:49:14.141] [undefined] GET(/:id/history): try to retrieve history of user 2
[2025-07-21 13:49:14.147] [undefined] GET(/:id/channel): try to retrieve channel of user 2
[2025-07-21 13:49:14.158] [undefined] GET(/:id/channel): failed to retrieve channel of user 2 because it doesn't exist with status 404
[2025-07-21 13:49:14.164] [undefined] GET(/:id/history): failed to retrieve history of user 2 because it doesn't exist with status 404
[2025-07-21 13:49:14.176] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200
[2025-07-21 13:49:27.835] [undefined] PUT(/:id): failed due to invalid values with status 400
[2025-07-21 13:53:11.927] [undefined] GET(/:id/channel): try to retrieve channel of user 2
[2025-07-21 13:53:11.928] [undefined] GET(/:id/history): try to retrieve history of user 2
[2025-07-21 13:53:11.934] [undefined] GET(/:id/channel): failed to retrieve channel of user 2 because it doesn't exist with status 404
[2025-07-21 13:53:11.939] [undefined] GET(/:id/history): failed to retrieve history of user 2 because it doesn't exist with status 404
[2025-07-21 13:53:11.961] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200
[2025-07-21 13:53:26.486] [undefined] PUT(/:id): failed due to invalid values with status 400
[2025-07-21 13:55:33.519] [undefined] GET(/:id/history): try to retrieve history of user 2
[2025-07-21 13:55:33.528] [undefined] GET(/:id/channel): try to retrieve channel of user 2
[2025-07-21 13:55:33.532] [undefined] GET(/:id/channel): failed to retrieve channel of user 2 because it doesn't exist with status 404
[2025-07-21 13:55:33.542] [undefined] GET(/:id/history): failed to retrieve history of user 2 because it doesn't exist with status 404
[2025-07-21 13:55:33.562] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200
[2025-07-21 13:55:44.670] [undefined] PUT(/:id): try to update user 2
[2025-07-21 13:55:44.684] [undefined] PUT(/:id): successfully updated user 2 with status 200
[2025-07-21 13:55:48.794] [undefined] GET(/:id/history): try to retrieve history of user 2
[2025-07-21 13:55:48.797] [undefined] GET(/:id/channel): try to retrieve channel of user 2
[2025-07-21 13:55:48.799] [undefined] GET(/:id/history): failed to retrieve history of user 2 because it doesn't exist with status 404
[2025-07-21 13:55:48.803] [undefined] GET(/:id/channel): failed to retrieve channel of user 2 because it doesn't exist with status 404
[2025-07-21 13:55:48.822] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200
[2025-07-21 13:56:33.755] [undefined] GET(/:id/history): try to retrieve history of user 2
[2025-07-21 13:56:33.763] [undefined] GET(/:id/channel): try to retrieve channel of user 2
[2025-07-21 13:56:33.771] [undefined] GET(/:id/history): failed to retrieve history of user 2 because it doesn't exist with status 404
[2025-07-21 13:56:33.782] [undefined] GET(/:id/channel): failed to retrieve channel of user 2 because it doesn't exist with status 404
[2025-07-21 13:56:33.804] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200
[2025-07-21 13:56:43.181] [undefined] POST(/login): try to login with username 'astria'
[2025-07-21 13:56:43.306] [undefined] POST(/login): Successfully logged in with status 200
[2025-07-21 13:56:56.291] [undefined] GET(/:id/channel): try to retrieve channel of user 2
[2025-07-21 13:56:56.313] [undefined] GET(/:id/channel): failed to retrieve channel of user 2 because it doesn't exist with status 404
[2025-07-21 13:56:56.344] [undefined] GET(/:id/history): try to retrieve history of user 2
[2025-07-21 13:56:56.354] [undefined] GET(/:id/history): failed to retrieve history of user 2 because it doesn't exist with status 404
[2025-07-21 13:56:56.363] [undefined] GET(/user/:id): Playlists retrieved for user with id 2 with status 200

9
docker-compose.yaml

@ -4,14 +4,13 @@ services:
build: build:
context: ./backend context: ./backend
dockerfile: Dockerfile dockerfile: Dockerfile
network: host
container_name: resit_backend container_name: resit_backend
ports: ports:
- "8000:8000" - "8000:8000"
environment: environment:
DB_USER: ${POSTGRES_USER} DB_USER: ${POSTGRES_USER}
DB_NAME: ${POSTGRES_DB} DB_NAME: ${POSTGRES_DB}
DB_HOST: ${POSTGRES_HOST} DB_HOST: db
DB_PASSWORD: ${POSTGRES_PASSWORD} DB_PASSWORD: ${POSTGRES_PASSWORD}
JWT_SECRET: ${JWT_SECRET} JWT_SECRET: ${JWT_SECRET}
LOG_FILE: ${LOG_FILE} LOG_FILE: ${LOG_FILE}
@ -35,12 +34,16 @@ services:
frontend: frontend:
image: nginx:latest image: nginx:latest
network_mode: host
ports: ports:
- "80:80" - "80:80"
- "443:443"
volumes: volumes:
- ./frontend/dist:/usr/share/nginx/html - ./frontend/dist:/usr/share/nginx/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./nginx/nginx-selfsigned.crt:/etc/nginx/ssl/nginx-selfsigned.crt
- ./nginx/nginx-selfsigned.key:/etc/nginx/ssl/nginx-selfsigned.key
depends_on:
- resit_backend
volumes: volumes:
db_data: db_data:

15
nginx/default.conf

@ -2,12 +2,25 @@ server {
server_name localhost; server_name localhost;
listen 80; listen 80;
return 301 https://$host$request_uri;
}
server {
server_name localhost;
listen 443 ssl;
root /usr/share/nginx/html; root /usr/share/nginx/html;
index index.html index.htm; index index.html index.htm;
ssl_certificate /etc/nginx/ssl/nginx-selfsigned.crt;
ssl_certificate_key /etc/nginx/ssl/nginx-selfsigned.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
# API routes - proxy to backend (MUST come before static file rules) # API routes - proxy to backend (MUST come before static file rules)
location /api/ { location /api/ {
proxy_pass http://127.0.0.1:8000; proxy_pass http://resit_backend:8000;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

23
nginx/nginx-selfsigned.crt

@ -0,0 +1,23 @@
-----BEGIN CERTIFICATE-----
MIID5zCCAs+gAwIBAgIUXzNzqa/12lyIcoxXf+v371J3fWkwDQYJKoZIhvcNAQEL
BQAwgYIxCzAJBgNVBAYTAkZSMREwDwYDVQQIDAhOb3JtYW5keTENMAsGA1UEBwwE
Q2FlbjERMA8GA1UECgwIRnJhbWluZm8xFTATBgNVBAMMDFNhY2hhIEdVRVJJTjEn
MCUGCSqGSIb3DQEJARYYc2FjaGEuZ3VlcmluQHN1cGluZm8uY29tMB4XDTI1MDcy
MTEzMzgwMVoXDTI2MDcyMTEzMzg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