<%

// "custom_routes.py" => "custom_router"
function fileName2routerName(filename) {
    return filename.replace(/_routes\.py$/, '_router')
}

// "custom_routes.py" => "custom_routes"
function removeExtension(filename) {
    return filename.replace(/\.py$/, '')
}

-%>
from fastapi import FastAPI, Request, status
from fastapi.responses import JSONResponse
from routes import router
<% customRouteFilenames.forEach(filename => { %>
from <%= removeExtension(filename) %> import router as <%= fileName2routerName(filename) %>
<% }) -%>

app = FastAPI()

@app.exception_handler(Exception)
async def exception_handler(request: Request, ex: Exception):
    return JSONResponse(
        status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
        content={"error": "Internal Server Error"}
    )

app.include_router(router)
<% customRouteFilenames.forEach(filename => { %>
app.include_router(<%= fileName2routerName(filename) %>)
<% }) -%>
