Skip to content

Commit

Permalink
fix(engine): Set CORS according to app env
Browse files Browse the repository at this point in the history
  • Loading branch information
topher-lo committed Mar 21, 2024
1 parent fbb8a26 commit ec3f622
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
15 changes: 10 additions & 5 deletions tracecat/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
authenticate_user,
authenticate_user_or_service,
)
from tracecat.config import TRACECAT__APP_ENV, TRACECAT__RUNNER_URL
from tracecat.db import (
Action,
ActionRun,
Expand Down Expand Up @@ -86,11 +87,15 @@ async def lifespan(app: FastAPI):

app = FastAPI(lifespan=lifespan)

# TODO: Check TRACECAT__APP_ENV to set origins
origins = [
"http://localhost:3000",
"http://localhost:8000",
]
if TRACECAT__APP_ENV == "prod":
# NOTE: If you are using Tracecat self-hosted
# please replace with your own domain
origins = ["https://platform.tracecat.com", TRACECAT__RUNNER_URL]
else:
origins = [
"http://localhost:3000",
"http://localhost:8000",
]

# TODO: Check TRACECAT__APP_ENV to set methods and headers
app.add_middleware(
Expand Down
19 changes: 13 additions & 6 deletions tracecat/runner/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from fastapi.responses import ORJSONResponse

from tracecat.auth import AuthenticatedAPIClient, Role, authenticate_service
from tracecat.config import TRACECAT__API_URL
from tracecat.config import TRACECAT__API_URL, TRACECAT__APP_ENV
from tracecat.contexts import ctx_session_role, ctx_workflow
from tracecat.logger import standard_logger
from tracecat.runner.actions import (
Expand All @@ -72,11 +72,18 @@

app = FastAPI(debug=True, default_response_class=ORJSONResponse)

# TODO: Check TRACECAT__APP_ENV to set origins
origins = [
"http://localhost:3000",
"http://localhost:8001",
]
if TRACECAT__APP_ENV == "prod":
# NOTE: If you are using Tracecat self-hosted
# please replace with your own domain
origins = [
"https://platform.tracecat.com",
TRACECAT__API_URL,
]
else:
origins = [
"http://localhost:3000",
"http://localhost:8000",
]

# TODO: Check TRACECAT__APP_ENV to set methods and headers
app.add_middleware(
Expand Down

0 comments on commit ec3f622

Please sign in to comment.