feat(PORT-004A): add workspace bootstrap and scoped settings
This commit is contained in:
17
app/main.py
17
app/main.py
@@ -12,10 +12,12 @@ from typing import Any
|
||||
|
||||
from fastapi import FastAPI, Request, WebSocket, WebSocketDisconnect
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import RedirectResponse
|
||||
from nicegui import ui # type: ignore[attr-defined]
|
||||
|
||||
import app.pages # noqa: F401
|
||||
from app.api.routes import router as api_router
|
||||
from app.models.workspace import WORKSPACE_COOKIE, get_workspace_repository
|
||||
from app.services.cache import CacheService
|
||||
from app.services.data_service import DataService
|
||||
from app.services.runtime import set_data_service
|
||||
@@ -146,6 +148,21 @@ async def health(request: Request) -> dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
@app.get("/workspaces/bootstrap", tags=["workspace"])
|
||||
async def bootstrap_workspace() -> RedirectResponse:
|
||||
workspace_id = get_workspace_repository().create_workspace_id()
|
||||
response = RedirectResponse(url=f"/{workspace_id}", status_code=303)
|
||||
response.set_cookie(
|
||||
key=WORKSPACE_COOKIE,
|
||||
value=workspace_id,
|
||||
httponly=True,
|
||||
samesite="lax",
|
||||
max_age=60 * 60 * 24 * 365,
|
||||
path="/",
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
@app.websocket("/ws/updates")
|
||||
async def websocket_updates(websocket: WebSocket) -> None:
|
||||
manager: ConnectionManager = websocket.app.state.ws_manager
|
||||
|
||||
Reference in New Issue
Block a user