dataset-tool / app /main.py
iaroy's picture
Deploy full application code
fdc5d7a
raw
history blame
1.33 kB
import logging
import json
from fastapi import FastAPI
from app.api import api_router
from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.gzip import GZipMiddleware
class JsonFormatter(logging.Formatter):
def format(self, record):
log_record = {
"level": record.levelname,
"time": self.formatTime(record, self.datefmt),
"name": record.name,
"message": record.getMessage(),
}
if record.exc_info:
log_record["exc_info"] = self.formatException(record.exc_info)
return json.dumps(log_record)
handler = logging.StreamHandler()
handler.setFormatter(JsonFormatter())
logging.basicConfig(level=logging.INFO, handlers=[handler])
app = FastAPI(title="Collinear API")
# Enable CORS for the frontend
frontend_origin = "http://localhost:5173"
app.add_middleware(
CORSMiddleware,
allow_origins=[frontend_origin],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.add_middleware(GZipMiddleware, minimum_size=1000)
app.include_router(api_router, prefix="/api")
@app.get("/")
async def root():
return {"message": "Welcome to the Collinear Data Tool API"}
if __name__ == "__main__":
import uvicorn
uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True)