30 lines
795 B
Python
30 lines
795 B
Python
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
from fastapi import Depends, FastAPI, HTTPException, Request, Security
|
|
from fastapi.security.api_key import APIKeyHeader
|
|
|
|
from .routers import health_router, scrape_router
|
|
|
|
API_KEY = os.getenv("API_KEY", "")
|
|
api_key_header = APIKeyHeader(name="X-API-Key", auto_error=False)
|
|
|
|
|
|
async def verify_api_key(key: str | None = Security(api_key_header)) -> None:
|
|
if API_KEY and key != API_KEY:
|
|
raise HTTPException(status_code=401, detail="Invalid or missing API key")
|
|
|
|
|
|
app = FastAPI(
|
|
title="Scrapling Service",
|
|
description="HTTP microservice exposing Scrapling web-scraping fetcherss to n8n",
|
|
version="0.1.0",
|
|
)
|
|
|
|
app.include_router(health_router)
|
|
app.include_router(
|
|
scrape_router,
|
|
dependencies=[Depends(verify_api_key)],
|
|
)
|