35 lines
1008 B
Python
35 lines
1008 B
Python
from pathlib import Path
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
from app.config import UPLOAD_DIR
|
|
from app.database import init_db
|
|
from app.routers import web, api
|
|
|
|
app = FastAPI(title="Mailova 星笺")
|
|
|
|
UPLOAD_DIR.mkdir(exist_ok=True)
|
|
|
|
|
|
# Cache-Control for uploaded images (30 days, immutable — filenames contain UUID)
|
|
@app.middleware("http")
|
|
async def cache_control_middleware(request, call_next):
|
|
response = await call_next(request)
|
|
if request.url.path.startswith("/uploads/"):
|
|
response.headers["Cache-Control"] = "public, max-age=2592000, immutable"
|
|
return response
|
|
|
|
|
|
app.mount("/static", StaticFiles(directory=str(Path(__file__).resolve().parent / "static")), name="static")
|
|
app.mount("/uploads", StaticFiles(directory=str(UPLOAD_DIR)), name="uploads")
|
|
|
|
app.include_router(web.router)
|
|
app.include_router(api.router)
|
|
|
|
init_db()
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True)
|