-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
48 lines (37 loc) · 1.26 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import uvicorn
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from sqlmodel import SQLModel
from starlette.responses import JSONResponse
from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY
from db import create_db_and_tables
from routers import assemblygroupmodules, assemblygroups, components, web, auth, biketypes
app = FastAPI(title="Bike configurator")
app.include_router(web.router)
app.include_router(biketypes.router, prefix="/api")
app.include_router(assemblygroups.router, prefix="/api")
app.include_router(assemblygroupmodules.router, prefix="/api")
app.include_router(components.router)
app.include_router(auth.router)
origins = [
"http://localhost:8000",
"http://localhost:8080",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.on_event("startup")
def on_startup():
create_db_and_tables()
@app.middleware("http")
async def add_cars_cookie(request: Request, call_next):
response = await call_next(request)
response.set_cookie(key="cars_cookie",
value="you_visited_the_carsharing_app")
return response
if __name__ == "__main__":
uvicorn.run("main:app", reload=True)