Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

Commit da5974a

Browse files
committed
Update examples
1 parent 85df9bc commit da5974a

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

examples/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ async def test(sid, *args, **kwargs):
1515
await sio.emit('hey', 'joe')
1616

1717

18-
1918
if __name__ == '__main__':
2019
import logging
2120
import sys
@@ -25,4 +24,4 @@ async def test(sid, *args, **kwargs):
2524

2625
import uvicorn
2726

28-
uvicorn.run("examples.app:app", host='0.0.0.0', port=8000, reload=True, debug=False)
27+
uvicorn.run("examples.app:app", host='0.0.0.0', port=8000)

examples/cors.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from fastapi import FastAPI
2+
from fastapi.middleware.cors import CORSMiddleware
3+
4+
from fastapi_socketio import SocketManager
5+
6+
app = FastAPI()
7+
# Adding the CORS middleware will overwrite SocketManager's CORS settings
8+
# Make sure to add the CORS middleware before SocketManager
9+
app.add_middleware(
10+
CORSMiddleware,
11+
allow_origins=["*"],
12+
allow_credentials=True,
13+
allow_methods=["*"],
14+
allow_headers=["*"],
15+
)
16+
sio = SocketManager(app=app, cors_allowed_origins="*")
17+
18+
19+
if __name__ == '__main__':
20+
import uvicorn
21+
22+
uvicorn.run("examples.cors:app", host='0.0.0.0', port=8000)

0 commit comments

Comments
 (0)