25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.py 823 B

1 년 전
1 년 전
1 년 전
123456789101112131415161718192021222324252627282930
  1. from fastapi import FastAPI
  2. from core.config import settings, createAdminAcc
  3. from db.session import engine
  4. from db.base import Base
  5. from apis.base import api_router
  6. from fastapi.middleware.cors import CORSMiddleware
  7. def include_routes(app): # include all routes from our api/v1/
  8. app.include_router(api_router)
  9. def startup(): # start the project, and create the tables
  10. app = FastAPI(
  11. title=settings.PROJECT_NAME,
  12. version=settings.PROJECT_VERSION,
  13. )
  14. Base.metadata.create_all(bind=engine)
  15. createAdminAcc()
  16. include_routes(app)
  17. return app
  18. origins = ["*"]
  19. app = startup()
  20. app.add_middleware(CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"])
  21. # Testing stuff
  22. @app.get("/")
  23. def root():
  24. return {"message": "Hello World!"}