Skip to content

Commit d921923

Browse files
committed
fix: setup CORS as a public API
1 parent 74fc1ea commit d921923

6 files changed

Lines changed: 4 additions & 18 deletions

File tree

.env

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ MEM_LIMIT=4294967296
4646

4747
# This is the name of a network possibly shared with other containers
4848
# on dev connect to the same network as off-server
49-
COMMON_NET_NAME=po_default
49+
COMMON_NET_NAME=po_off_default
5050

5151
# Sentry DNS for bug tracking, used only in staging and production
5252
SENTRY_DNS=
@@ -57,7 +57,3 @@ LOG_LEVEL=DEBUG
5757
# Path to the yaml configuration file
5858
# This envvar is **required**
5959
CONFIG_PATH=
60-
61-
62-
# For local development only allow CORS from localhost. Set to '*' to allow all remote access.
63-
ALLOWED_ORIGINS='http://localhost,http://127.0.0.1'

.github/workflows/container-deploy.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ jobs:
3838
# in staging Product Opener is deployed on the same VM
3939
echo "COMMON_NET_NAME=po_webnet" >> $GITHUB_ENV
4040
echo "OFF_API_URL=https://world.openfoodfacts.net" >> $GITHUB_ENV
41-
echo "ALLOWED_ORIGINS='*'" >> $GITHUB_ENV
42-
4341
echo "REDIS_HOST=redis" >> $GITHUB_ENV
4442
- name: Set various variable for production deployment
4543
if: matrix.env == 'off-search-org'
@@ -50,7 +48,6 @@ jobs:
5048
# separate server and is not dockerized
5149
echo "COMMON_NET_NAME=po_webnet" >> $GITHUB_ENV
5250
echo "OFF_API_URL=https://world.openfoodfacts.org" >> $GITHUB_ENV
53-
echo "ALLOWED_ORIGINS='*'" >> $GITHUB_ENV
5451
# REDIS_HOST: this is the IP address of the stunnel VM
5552
echo "REDIS_HOST=10.1.0.113" >> $GITHUB_ENV
5653
- name: Wait for search service image container build workflow
@@ -165,7 +162,6 @@ jobs:
165162
echo "SENTRY_DNS=${{ secrets.SENTRY_DSN }}" >> .env
166163
echo "CONFIG_PATH=data/config/openfoodfacts.yml" >> .env
167164
echo "OFF_API_URL=${{ env.OFF_API_URL }}" >> .env
168-
echo "ALLOWED_ORIGINS=${{ env.ALLOWED_ORIGINS }}" >> .env
169165
170166
- name: Create Docker volumes
171167
uses: appleboy/ssh-action@master

.github/workflows/pre-commit.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ jobs:
1818
echo "" > .envrc
1919
echo CONFIG_PATH=data/config/openfoodfacts.yml >> .envrc
2020
echo OFF_API_URL=https://world.openfoodfacts.org >> .envrc
21-
echo ALLOWED_ORIGINS='http://localhost,http://127.0.0.1' >> .envrc
2221
echo USER_IID=$(id -u) >>.envrc
2322
echo USER_GID=$(id -g) >>.envrc
2423
make build

app/api.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import os
32
from pathlib import Path
43
from typing import Annotated, Any, cast
54

@@ -53,14 +52,12 @@
5352
},
5453
description=API_DESCRIPTION,
5554
)
56-
ALLOWED_ORIGINS = os.environ.get(
57-
"ALLOWED_ORIGINS", "http://localhost,http://127.0.0.1"
58-
).split(",")
5955
app.add_middleware(
6056
CORSMiddleware,
61-
allow_origins=ALLOWED_ORIGINS,
57+
# this is a public API
58+
allow_origin_regex="https?://.*",
6259
allow_credentials=True,
63-
allow_methods=["*"],
60+
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"],
6461
allow_headers=["*"],
6562
)
6663
templates = Jinja2Templates(directory=Path(__file__).parent / "templates")

docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ x-api-common: &api-common
4545
- CONFIG_PATH
4646
# URL of the OFF API
4747
- OFF_API_URL
48-
- ALLOWED_ORIGINS
4948
networks:
5049
- default
5150
- common_net

docs/devs/how-to-install.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export USER_UID=<your_user_uid>
4242

4343
export CONFIG_PATH=data/config/openfoodfacts.yml
4444
export OFF_API_URL=https://world.openfoodfacts.org
45-
export ALLOWED_ORIGINS='http://localhost,http://127.0.0.1'
4645
```
4746

4847
[^winEnvrc]: For Windows users, the .envrc is only taken into account by the `make` commands.

0 commit comments

Comments
 (0)