From 6ed47b667ca61f87bfec88cf4801a8c1e2148b9f Mon Sep 17 00:00:00 2001 From: nihonium Date: Sun, 26 Oct 2025 04:06:38 +0300 Subject: [PATCH] feat: proxy api requests via frontend --- Dockerfiles/Dockerfile_frontend | 1 + api/openapi.yaml | 2 +- modules/frontend/nginx-default.conf | 29 ++++++++++++++++++++++++ modules/frontend/src/api/core/OpenAPI.ts | 2 +- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 modules/frontend/nginx-default.conf diff --git a/Dockerfiles/Dockerfile_frontend b/Dockerfiles/Dockerfile_frontend index a7ec893..18bc6d7 100644 --- a/Dockerfiles/Dockerfile_frontend +++ b/Dockerfiles/Dockerfile_frontend @@ -1,4 +1,5 @@ FROM nginx:alpine COPY modules/frontend/dist /usr/share/nginx/html +COPY modules/frontend/nginx-default.conf /etc/nginx/conf.d/default.conf EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/api/openapi.yaml b/api/openapi.yaml index 97fa3a4..b20f677 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -3,7 +3,7 @@ info: title: Titles, Users, Reviews, Tags, and Media API version: 1.0.0 servers: - - url: https://api.example.com + - url: /api/v1 paths: # /title: # get: diff --git a/modules/frontend/nginx-default.conf b/modules/frontend/nginx-default.conf new file mode 100644 index 0000000..a538968 --- /dev/null +++ b/modules/frontend/nginx-default.conf @@ -0,0 +1,29 @@ +server { + listen 80; + listen [::]:80; + server_name localhost; + + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } + + location /api/v1/ { + rewrite ^/api/v1/(.*)$ /$1 break; + proxy_pass http://nyanimedb-backend:8080/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + #error_page 404 /404.html; + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + +} \ No newline at end of file diff --git a/modules/frontend/src/api/core/OpenAPI.ts b/modules/frontend/src/api/core/OpenAPI.ts index 4fb2299..185e5c3 100644 --- a/modules/frontend/src/api/core/OpenAPI.ts +++ b/modules/frontend/src/api/core/OpenAPI.ts @@ -20,7 +20,7 @@ export type OpenAPIConfig = { }; export const OpenAPI: OpenAPIConfig = { - BASE: 'https://api.example.com', + BASE: '/api/v1', VERSION: '1.0.0', WITH_CREDENTIALS: false, CREDENTIALS: 'include',