first commit
This commit is contained in:
43
main.py
Normal file
43
main.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from contextlib import asynccontextmanager
|
||||
from routes import auth, info, order, payment
|
||||
import os
|
||||
from config import load_config
|
||||
from database import engine, Base
|
||||
|
||||
|
||||
ApplicationConfig = load_config()
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
# Startup: Create database tables
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
yield
|
||||
# Shutdown: cleanup if needed
|
||||
|
||||
app = FastAPI(title="Oil Customer Gateway API", version="1.0.0", lifespan=lifespan)
|
||||
|
||||
app.include_router(auth, prefix="/auth", tags=["auth"])
|
||||
app.include_router(info, prefix="/info", tags=["info"])
|
||||
app.include_router(order, prefix="/order", tags=["order"])
|
||||
app.include_router(payment, prefix="/payment", tags=["payment"])
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {"message": "Oil Customer Gateway API", "status": "Api is online"}
|
||||
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=ApplicationConfig.origins,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# Mount static files for uploaded images
|
||||
app.mount("/images", StaticFiles(directory="/images"), name="images")
|
||||
Reference in New Issue
Block a user