feat: initial commit
This commit is contained in:
29
service/main.py
Normal file
29
service/main.py
Normal file
@@ -0,0 +1,29 @@
|
||||
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)],
|
||||
)
|
||||
Reference in New Issue
Block a user