-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (48 loc) · 1.74 KB
/
Copy pathmain.py
File metadata and controls
55 lines (48 loc) · 1.74 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
53
54
55
from app import __version__
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from fastapi.exceptions import RequestValidationError
from app.utils.make_meta import make_meta
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
import os
from app.api.routes import router
app = FastAPI(
title="Python°",
description="FastAPI, Postgres, tsvector",
version=__version__,
)
# CORS middleware for development
app.add_middleware(
CORSMiddleware,
allow_origins=[
"http://localhost:1999",
"http://localhost:1980",
"http://localhost:2027",
"http://localhost:2020",
"http://localhost:2000",
"https://goldlabel.pro",
"https://nx-admin.goldlabel.pro",
"https://free.goldlabel.pro",
"https://listingslab.com",
"https://ed-tech.co",
"https://notheretofuckspiders.art",
],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"]
)
# Global validation error handler for make_meta pattern
@app.exception_handler(RequestValidationError)
async def validation_exception_handler(request: Request, exc: RequestValidationError):
msg = exc.errors()[0]['msg'] if exc.errors() else str(exc)
return JSONResponse(status_code=422, content={"meta": make_meta("error", msg)})
app.include_router(router)
# Mount static directory
app.mount("/static", StaticFiles(directory=os.path.join(os.path.dirname(__file__), "static")), name="static")
# Favicon route
@app.get("/favicon.ico", include_in_schema=False)
async def favicon():
favicon_path = os.path.join(os.path.dirname(__file__), "static", "favicon.ico")
return FileResponse(favicon_path)