40 lines
907 B
Python
40 lines
907 B
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from src.config import ALLOWED_ORIGINS
|
|
from src.database import init_db
|
|
from src.routers import init, login, status
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""Initialize database on startup."""
|
|
init_db()
|
|
yield
|
|
|
|
|
|
app = FastAPI(
|
|
title="Archivium Local Backend",
|
|
description="Local archive encryption and authentication system",
|
|
version="0.1.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=ALLOWED_ORIGINS,
|
|
allow_credentials=True,
|
|
allow_methods=["POST", "GET"],
|
|
allow_headers=["Content-Type"],
|
|
)
|
|
|
|
app.include_router(init.router)
|
|
app.include_router(login.router)
|
|
app.include_router(status.router)
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run(app, host="127.0.0.1", port=8000)
|