Created
April 3, 2022 14:33
-
-
Save arshamalh/f9a069d86611b50b9854a07f44da5859 to your computer and use it in GitHub Desktop.
Boilerplate for FastAPI returning UI, CORS, routers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fastapi import FastAPI | |
from fastapi.middleware.cors import CORSMiddleware | |
from fastapi.staticfiles import StaticFiles | |
from routes import routes_group_1, routes_group_2 | |
api_app = FastAPI(title="api app") | |
api_app.add_middleware( | |
CORSMiddleware, | |
allow_origins=["*"], | |
allow_credentials=True, | |
allow_methods=["*"], | |
allow_headers=["*"], | |
) | |
api_app.include_router(routes_group_1.router) | |
api_app.include_router(routes_group_2.router) | |
app = FastAPI(title="main app") | |
app.mount('/api', api_app) | |
app.mount("/", StaticFiles(directory="ui", html=True), name="ui") | |
# If project structure is like: | |
# ├── main.py | |
# ├── ui | |
# │ ├── index.html | |
# │ ├── style.css | |
# │ ├── script.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment