From e24116988c35a34706687205634f9711c164f813 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Tue, 4 Jul 2023 11:21:18 +0300 Subject: [PATCH] CORS setup for docker-compose config with new frontend (#7841) * CORS setup for docker-compose with new frontend * Add NEXT_PUBLIC_API_WEBSOCKET_PROTOCOL=ws for docker compose with new frontend --- CHANGELOG.md | 1 + docker-compose/envs/common-frontend.env | 5 +- docker-compose/proxy/nginx.conf | 51 ++++++++++++++++--- .../services/docker-compose-nginx.yml | 4 +- 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73378e7d95..6e28bf394b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ ### Chore +- [#7841](https://github.com/blockscout/blockscout/pull/7841) - CORS setup for docker-compose config with new frontend - [#7832](https://github.com/blockscout/blockscout/pull/7832) - API v2: Add block_number to logs - [#7789](https://github.com/blockscout/blockscout/pull/7789) - Fix test warnings; Fix name of `MICROSERVICE_ETH_BYTECODE_DB_INTERVAL_BETWEEN_LOOKUPS` env variable - [#7819](https://github.com/blockscout/blockscout/pull/7819) - Add logging for unknown error verification result diff --git a/docker-compose/envs/common-frontend.env b/docker-compose/envs/common-frontend.env index 9f75a9c50e..84da58952b 100644 --- a/docker-compose/envs/common-frontend.env +++ b/docker-compose/envs/common-frontend.env @@ -1,7 +1,7 @@ NEXT_PUBLIC_API_HOST=localhost -NEXT_PUBLIC_STATS_API_HOST=http://localhost -NEXT_PUBLIC_API_PORT=80 +NEXT_PUBLIC_API_PORT=81 NEXT_PUBLIC_API_PROTOCOL=http +NEXT_PUBLIC_STATS_API_HOST=http://localhost:82 NEXT_PUBLIC_NETWORK_NAME=Göerli NEXT_PUBLIC_NETWORK_SHORT_NAME=Göerli NEXT_PUBLIC_NETWORK_ASSETS_PATHNAME=ethereum @@ -23,3 +23,4 @@ NEXT_PUBLIC_NETWORK_LOGO=https://raw.githubusercontent.com/blockscout/frontend-c NEXT_PUBLIC_NETWORK_ICON=https://raw.githubusercontent.com/blockscout/frontend-configs/main/configs/network-icons/goerli.svg NEXT_PUBLIC_HOMEPAGE_PLATE_GRADIENT="radial-gradient(103.03% 103.03% at 0% 0%, rgba(183, 148, 244, 0.8) 0%, rgba(0, 163, 196, 0.8) 100%)" NEXT_PUBLIC_HOMEPAGE_PLATE_TEXT_COLOR="rgb(255, 255, 255)" +NEXT_PUBLIC_API_WEBSOCKET_PROTOCOL='ws' diff --git a/docker-compose/proxy/nginx.conf b/docker-compose/proxy/nginx.conf index 1b88890635..d20a44c819 100644 --- a/docker-compose/proxy/nginx.conf +++ b/docker-compose/proxy/nginx.conf @@ -5,17 +5,52 @@ server { location / { proxy_pass http://frontend:3000; } - location /api/v2 { - proxy_pass http://backend:4000/api/v2; + location /socket/v2 { + proxy_pass http://backend:4000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + } + location /api/ { + proxy_pass http://backend:4000/api; } - location /api/account/v1 { - proxy_pass http://backend:4000/api/account/v1; +} + +server { + listen 81; + server_name localhost; + proxy_http_version 1.1; + proxy_hide_header Access-Control-Allow-Origin; + proxy_hide_header Access-Control-Allow-Methods; + add_header 'Access-Control-Allow-Origin' 'http://localhost' always; + add_header 'Access-Control-Allow-Methods' 'PUT, GET, POST, OPTIONS, DELETE, PATCH' always; + + location / { + proxy_pass http://backend:4000; } - location /api/v1/counters { - proxy_pass http://stats:8050/api/v1/counters; + + location /socket { + proxy_pass http://backend:4000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; } - location /api/v1/lines { - proxy_pass http://stats:8050/api/v1/lines; +} + +server { + listen 82; + server_name localhost; + proxy_http_version 1.1; + proxy_hide_header Access-Control-Allow-Origin; + proxy_hide_header Access-Control-Allow-Methods; + add_header 'Access-Control-Allow-Origin' 'http://localhost' always; + add_header 'Access-Control-Allow-Credentials' 'true' always; + add_header 'Access-Control-Allow-Methods' 'PUT, GET, POST, OPTIONS, DELETE, PATCH' always; + + location / { + proxy_pass http://stats:8050; } location /socket/v2 { proxy_pass http://backend:4000; diff --git a/docker-compose/services/docker-compose-nginx.yml b/docker-compose/services/docker-compose-nginx.yml index 79ede9d962..2d2bd87dc1 100644 --- a/docker-compose/services/docker-compose-nginx.yml +++ b/docker-compose/services/docker-compose-nginx.yml @@ -9,4 +9,6 @@ services: target: /etc/nginx/conf.d/default.conf read_only: true ports: - - 80:80 \ No newline at end of file + - 80:80 + - 81:81 + - 82:82 \ No newline at end of file