| import asyncio |
| import os |
| from fastapi import FastAPI |
| from fastapi.staticfiles import StaticFiles |
| from fastapi.responses import FileResponse |
| from contextlib import asynccontextmanager |
|
|
| from config.logging import get_logger |
| from storage.db import init_db |
| from scheduler.runner import start_scheduler |
| from api.routes import router |
| from config.settings import HOST, PORT |
|
|
| logger = get_logger("main") |
|
|
| @asynccontextmanager |
| async def lifespan(app: FastAPI): |
| |
| logger.info("Starting WebGuard application...") |
| init_db() |
| start_scheduler() |
| os.makedirs("screenshots", exist_ok=True) |
| os.makedirs("recordings", exist_ok=True) |
| logger.info("WebGuard startup complete.") |
| yield |
| logger.info("Shutting down WebGuard...") |
| |
|
|
|
|
| app = FastAPI( |
| title="WebGuard", |
| description="Full-stack website monitoring with AI analysis", |
| version="1.0.0", |
| lifespan=lifespan, |
| ) |
|
|
| |
| app.include_router(router) |
|
|
| |
| app.mount("/screenshots", StaticFiles(directory="screenshots"), name="screenshots") |
|
|
| |
| app.mount("/static", StaticFiles(directory="frontend"), name="static") |
|
|
|
|
| @app.get("/") |
| async def root(): |
| return FileResponse("frontend/index.html") |
|
|
|
|
| if __name__ == "__main__": |
| import uvicorn |
| uvicorn.run("app:app", host=HOST, port=PORT, reload=False) |
|
|