Skip to content

Commit 74f8d37

Browse files
committed
Fix embed API routing and CORS origins
1 parent 50f7a71 commit 74f8d37

File tree

6 files changed

+153
-2
lines changed

6 files changed

+153
-2
lines changed

conf/compose/prod_docker_compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ services:
164164
- INTELLIGENCE_BASE_URL=https://cleanapp.io
165165
- EMAIL_SERVICE_URL=http://cleanapp_email_service:8080
166166
- INTERNAL_ADMIN_TOKEN=${INTERNAL_ADMIN_TOKEN}
167+
- ALLOWED_ORIGINS=https://cleanapp.io,https://www.cleanapp.io,https://embed.cleanapp.io,https://www.embed.cleanapp.io
168+
- WEBSOCKET_ALLOWED_ORIGINS=https://cleanapp.io,https://www.cleanapp.io,https://embed.cleanapp.io,https://www.embed.cleanapp.io
167169
- MOBILE_PUSH_ENABLED=${MOBILE_PUSH_ENABLED:-false}
168170
- APNS_TEAM_ID=${APNS_TEAM_ID}
169171
- APNS_KEY_ID=${APNS_KEY_ID}

conf/nginx/prod/conf.d/embeddedcleanapp.conf

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,61 @@ server {
77
ssl_certificate_key /etc/nginx/conf.d/STAR_cleanapp_io.key;
88
ssl_session_cache shared:SSL:10m;
99

10+
# API v3 routes to report-listener (v3) on 9081
11+
location /api/v3/ {
12+
proxy_pass http://127.0.0.1:9081;
13+
proxy_http_version 1.1;
14+
proxy_set_header Host $host;
15+
proxy_set_header Upgrade $http_upgrade;
16+
proxy_set_header Connection "upgrade";
17+
proxy_read_timeout 86400;
18+
}
19+
20+
# API v4 routes to report-listener-v4 on 9097
21+
location /api/v4/ {
22+
proxy_pass http://127.0.0.1:9097;
23+
proxy_http_version 1.1;
24+
proxy_set_header Host $host;
25+
proxy_set_header Upgrade $http_upgrade;
26+
proxy_set_header Connection "upgrade";
27+
proxy_read_timeout 86400;
28+
}
29+
30+
# Next.js API routes - proxy to main frontend, not the static embedded shell
31+
location /api/reports/ {
32+
proxy_pass http://127.0.0.1:3001;
33+
proxy_set_header Host $host;
34+
proxy_http_version 1.1;
35+
proxy_set_header Upgrade $http_upgrade;
36+
proxy_set_header Connection "upgrade";
37+
}
38+
39+
location /api/reports-count {
40+
proxy_pass http://127.0.0.1:3001;
41+
proxy_set_header Host $host;
42+
}
43+
44+
location /api/geocode {
45+
proxy_pass http://127.0.0.1:3001;
46+
proxy_set_header Host $host;
47+
}
48+
49+
location /api/osm-search {
50+
proxy_pass http://127.0.0.1:3001;
51+
proxy_set_header Host $host;
52+
}
53+
54+
location /api/places-search {
55+
proxy_pass http://127.0.0.1:3001;
56+
proxy_set_header Host $host;
57+
}
58+
59+
# Other legacy API routes to customer service
60+
location /api/ {
61+
proxy_pass http://127.0.0.1:9080;
62+
proxy_set_header Host $host;
63+
}
64+
1065
location / {
1166
proxy_pass http://127.0.0.1:3002;
1267
proxy_set_header Host $host;

conf/nginx/prod/conf.d/livecleanapp.conf

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,55 @@ server {
33
server_name live.cleanapp.io www.live.cleanapp.io;
44
ssl_certificate /etc/nginx/conf.d/STAR_cleanapp_io_chain.crt;
55
ssl_certificate_key /etc/nginx/conf.d/STAR_cleanapp_io.key;
6-
location / {
6+
set $cors_origin "";
7+
if ($http_origin ~* "^https://(www\\.)?(cleanapp|embed\\.cleanapp)\\.io$") {
8+
set $cors_origin $http_origin;
9+
}
10+
11+
location /api/v3/ {
12+
proxy_hide_header 'Access-Control-Allow-Origin';
13+
add_header 'Access-Control-Allow-Origin' "$cors_origin" always;
14+
add_header 'Vary' 'Origin' always;
15+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
16+
add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Authorization' always;
17+
add_header 'Access-Control-Allow-Credentials' 'true' always;
18+
19+
if ($request_method = 'OPTIONS') {
20+
return 204;
21+
}
22+
723
proxy_pass http://127.0.0.1:9081;
824
proxy_http_version 1.1;
25+
proxy_set_header Host $host;
926
proxy_set_header Upgrade $http_upgrade;
1027
proxy_set_header Connection "upgrade";
1128
proxy_read_timeout 86400;
1229
}
1330

1431
# v4 API routed to report-listener-v4
1532
location /api/v4/ {
33+
proxy_hide_header 'Access-Control-Allow-Origin';
34+
add_header 'Access-Control-Allow-Origin' "$cors_origin" always;
35+
add_header 'Vary' 'Origin' always;
36+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
37+
add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Authorization' always;
38+
add_header 'Access-Control-Allow-Credentials' 'true' always;
39+
40+
if ($request_method = 'OPTIONS') {
41+
return 204;
42+
}
43+
1644
proxy_pass http://127.0.0.1:9097;
1745
proxy_http_version 1.1;
46+
proxy_set_header Host $host;
47+
proxy_set_header Upgrade $http_upgrade;
48+
proxy_set_header Connection "upgrade";
49+
proxy_read_timeout 86400;
50+
}
51+
52+
location / {
53+
proxy_pass http://127.0.0.1:9081;
54+
proxy_http_version 1.1;
1855
proxy_set_header Upgrade $http_upgrade;
1956
proxy_set_header Connection "upgrade";
2057
proxy_read_timeout 86400;

platform_blueprint/deploy/prod/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ services:
162162
- INTELLIGENCE_BASE_URL=https://cleanapp.io
163163
- EMAIL_SERVICE_URL=http://cleanapp_email_service:8080
164164
- INTERNAL_ADMIN_TOKEN=${INTERNAL_ADMIN_TOKEN}
165+
- ALLOWED_ORIGINS=https://cleanapp.io,https://www.cleanapp.io,https://embed.cleanapp.io,https://www.embed.cleanapp.io
166+
- WEBSOCKET_ALLOWED_ORIGINS=https://cleanapp.io,https://www.cleanapp.io,https://embed.cleanapp.io,https://www.embed.cleanapp.io
165167
ports:
166168
- 127.0.0.1:9081:8080
167169
depends_on:

platform_blueprint/deploy/prod/nginx_conf_d/embeddedcleanapp.conf

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,61 @@ server {
77
ssl_certificate_key /etc/nginx/conf.d/STAR_cleanapp_io.key;
88
ssl_session_cache shared:SSL:10m;
99

10+
# API v3 routes to report-listener (v3) on 9081
11+
location /api/v3/ {
12+
proxy_pass http://127.0.0.1:9081;
13+
proxy_http_version 1.1;
14+
proxy_set_header Host $host;
15+
proxy_set_header Upgrade $http_upgrade;
16+
proxy_set_header Connection "upgrade";
17+
proxy_read_timeout 86400;
18+
}
19+
20+
# API v4 routes to report-listener-v4 on 9097
21+
location /api/v4/ {
22+
proxy_pass http://127.0.0.1:9097;
23+
proxy_http_version 1.1;
24+
proxy_set_header Host $host;
25+
proxy_set_header Upgrade $http_upgrade;
26+
proxy_set_header Connection "upgrade";
27+
proxy_read_timeout 86400;
28+
}
29+
30+
# Next.js API routes - proxy to main frontend, not the static embedded shell
31+
location /api/reports/ {
32+
proxy_pass http://127.0.0.1:3001;
33+
proxy_set_header Host $host;
34+
proxy_http_version 1.1;
35+
proxy_set_header Upgrade $http_upgrade;
36+
proxy_set_header Connection "upgrade";
37+
}
38+
39+
location /api/reports-count {
40+
proxy_pass http://127.0.0.1:3001;
41+
proxy_set_header Host $host;
42+
}
43+
44+
location /api/geocode {
45+
proxy_pass http://127.0.0.1:3001;
46+
proxy_set_header Host $host;
47+
}
48+
49+
location /api/osm-search {
50+
proxy_pass http://127.0.0.1:3001;
51+
proxy_set_header Host $host;
52+
}
53+
54+
location /api/places-search {
55+
proxy_pass http://127.0.0.1:3001;
56+
proxy_set_header Host $host;
57+
}
58+
59+
# Other legacy API routes to customer service
60+
location /api/ {
61+
proxy_pass http://127.0.0.1:9080;
62+
proxy_set_header Host $host;
63+
}
64+
1065
location / {
1166
proxy_pass http://127.0.0.1:3002;
1267
proxy_set_header Host $host;

platform_blueprint/deploy/prod/nginx_conf_d/livecleanapp.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ server {
44
ssl_certificate /etc/nginx/conf.d/STAR_cleanapp_io_chain.crt;
55
ssl_certificate_key /etc/nginx/conf.d/STAR_cleanapp_io.key;
66
set $cors_origin "";
7-
if ($http_origin ~* "^https://(www\\.)?cleanapp\\.io$") {
7+
if ($http_origin ~* "^https://(www\\.)?(cleanapp|embed\\.cleanapp)\\.io$") {
88
set $cors_origin $http_origin;
99
}
1010

0 commit comments

Comments
 (0)