-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
52 lines (36 loc) · 1.12 KB
/
main.py
File metadata and controls
52 lines (36 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import uvicorn
from fastapi import FastAPI, HTTPException, Query
from fastapi.middleware.cors import CORSMiddleware
from controllers.crawler_controller import router as crawler_router
from database.database import init_db
app = FastAPI(
title="Web Crawler API",
description="A scalable web crawler API for extracting metadata and topics from URLs",
version="1.0.0",
)
# CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Initialize database
@app.on_event("startup")
async def startup_event():
await init_db()
@app.on_event("shutdown")
async def shutdown_event():
from database.database import close_db
await close_db()
# Include routers
app.include_router(crawler_router, prefix="/api/v1", tags=["crawler"])
@app.get("/")
async def root():
return {"message": "Web Crawler API", "docs": "/docs", "health": "/health"}
@app.get("/health")
async def health_check():
return {"status": "healthy"}
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)