mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Working on user, backend.
This commit is contained in:
+22
-17
@@ -1,29 +1,34 @@
|
||||
import os
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
from starlette.middleware.trustedhost import TrustedHostMiddleware
|
||||
from starlette.staticfiles import StaticFiles
|
||||
from fastapi.responses import FileResponse
|
||||
from database import BaseModel, engine
|
||||
from middleware.db_connection import DatabaseSessionMiddleware
|
||||
|
||||
from routes.main import api_router
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
app = FastAPI()
|
||||
from settings import config
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
print("Initialising database...")
|
||||
BaseModel.metadata.create_all(bind=engine)
|
||||
print("Database initialised!")
|
||||
yield
|
||||
print("App shutdown!")
|
||||
|
||||
|
||||
middlewares = []
|
||||
|
||||
app = FastAPI(lifespan=lifespan, middleware=middlewares)
|
||||
|
||||
|
||||
app.add_middleware(DatabaseSessionMiddleware)
|
||||
app.add_middleware(TrustedHostMiddleware, allowed_hosts=config.ALLOWED_HOSTS)
|
||||
|
||||
app.include_router(api_router)
|
||||
|
||||
if os.getenv("ENV") == "production":
|
||||
app.mount("/assets", StaticFiles(directory="static/assets"), name="assets")
|
||||
app.mount("/static", StaticFiles(directory="static", html=True), name="static")
|
||||
|
||||
|
||||
@app.get("/{full_path:path}")
|
||||
def read_react_app(full_path: str):
|
||||
return FileResponse("static/index.html")
|
||||
|
||||
Reference in New Issue
Block a user