Skip to content

Commit

Permalink
feat(app) add CORS support
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Sep 13, 2024
1 parent ddbcd80 commit 837882a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
5 changes: 2 additions & 3 deletions skynet/metrics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from fastapi import FastAPI

from skynet.env import enable_metrics, modules
from skynet.logs import get_logger
from skynet.modules.monitoring import (
Expand All @@ -10,9 +8,10 @@
)
from skynet.modules.ttt.summaries.jobs import PENDING_JOBS_KEY
from skynet.modules.ttt.summaries.persistence import db
from skynet.utils import create_app

log = get_logger(__name__)
metrics = FastAPI()
metrics = create_app()

if enable_metrics:

Expand Down
2 changes: 1 addition & 1 deletion skynet/modules/stt/streaming_whisper/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
log = get_logger(__name__)

ws_connection_manager = ConnectionManager()
app = FastAPI()
app = FastAPI() # No need for CORS middleware


@app.websocket('/ws/{meeting_id}')
Expand Down
5 changes: 2 additions & 3 deletions skynet/modules/ttt/summaries/app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from fastapi import FastAPI
from fastapi_versionizer.versionizer import Versionizer

from skynet.auth.openai import setup_credentials

from skynet.logs import get_logger
from skynet.modules.ttt.openai_api.app import destroy as destroy_openai_api, initialize as initialize_openai_api
from skynet.utils import create_app

from .jobs import start_monitoring_jobs
from .persistence import db
Expand All @@ -14,7 +13,7 @@

log = get_logger(__name__)

app = FastAPI()
app = create_app()
app.include_router(v1_router)

Versionizer(app=app, prefix_format='/v{major}', sort_routes=True).versionize()
Expand Down
17 changes: 15 additions & 2 deletions skynet/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import uvicorn
from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, FastAPI
from fastapi.middleware.cors import CORSMiddleware

from skynet.auth.bearer import JWTBearer
from skynet.env import bypass_auth, ws_max_ping_interval, ws_max_ping_timeout, ws_max_queue_size, ws_max_size_bytes
from skynet.logs import get_logger, uvicorn_log_config

log = get_logger(__name__)

dependencies = [] if bypass_auth else [Depends(JWTBearer())]

def create_app():
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_methods=["*"],
allow_headers=["*"],
)

return app


dependencies = [] if bypass_auth else [Depends(JWTBearer())]
responses = (
{}
if bypass_auth
Expand Down

0 comments on commit 837882a

Please sign in to comment.