Coverage for docs_src/cors/tutorial001.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from fastapi import FastAPI 1abcde

2from fastapi.middleware.cors import CORSMiddleware 1abcde

3 

4app = FastAPI() 1abcde

5 

6origins = [ 1abcde

7 "http://localhost.tiangolo.com", 

8 "https://localhost.tiangolo.com", 

9 "http://localhost", 

10 "http://localhost:8080", 

11] 

12 

13app.add_middleware( 1abcde

14 CORSMiddleware, 

15 allow_origins=origins, 

16 allow_credentials=True, 

17 allow_methods=["*"], 

18 allow_headers=["*"], 

19) 

20 

21 

22@app.get("/") 1abcde

23async def main(): 1abcde

24 return {"message": "Hello World"} 1abcde