from multiprocessing import Process from typing import Any from fastapi import FastAPI from fastapi.responses import HTMLResponse from starlette.middleware.cors import CORSMiddleware from starlette.middleware.trustedhost import TrustedHostMiddleware from jb.config import settings from jb.settings import BASE_HTML from jb.views.auth import auth_router from jb.views.common import common_router app = FastAPI( servers=[ { "url": "https://jamesbillings67.com/", "description": "Production environment", }, ], title="jb", version="1.0.0", ) app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) app.add_middleware(TrustedHostMiddleware, allowed_hosts=["*"]) app.include_router(router=common_router) app.include_router(router=auth_router) @app.get("/robots.txt") @app.get("/sitemap.xml") @app.get("/favicon.ico") def return_nothing() -> dict[str, Any]: return {} @app.get("/{full_path:path}") def serve_react_app(full_path: str): # This serves index.html for any unmatched route # React Router will then handle the client-side routing return HTMLResponse(BASE_HTML) def schedule_tasks(): from jb.flow.events import process_mturk_events_task from jb.flow.tasks import refill_hits_task Process(target=process_mturk_events_task).start() Process(target=refill_hits_task).start() if not settings.debug: schedule_tasks()