Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions evolver/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from http import HTTPStatus

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse, ORJSONResponse
from pydantic import ValidationError

Expand Down Expand Up @@ -41,6 +42,15 @@ async def lifespan(app: FastAPI):


app = FastAPI(lifespan=lifespan, default_response_class=ORJSONResponse)

app.add_middleware(
CORSMiddleware,
allow_origin_regex=r"https?://(localhost|127\.0\.0\.1)(:\d+)?",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep this in the AppSettings? In the settings we could also store the list of allowed origins (defaulting to [] and used here for allowed_origins), so then the change here would be complete and no need to update later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good idea. appsettings makes sense for this.

allow_methods=["*"],
allow_headers=["*"],
allow_credentials=True,
)

app.state.evolver = None
app.state.loop_trigger = threading.Event() # enables on-demand re-executon of the loop

Expand Down