Repository: Significant-Gravitas/Auto-GPT
File: autogpt_platform/backend/backend/server/rest_api.py (Python)

Code before:
)

app.include_router(
    backend.server.v2.postmark.postmark.router,
    tags=["v2", "email"],
    prefix="/api/email",
)

app.mount("/external-api", external_app)


@app.get(path="/health", tags=["health"], dependencies=[])
async def health():
    return {"status": "healthy"}


class AgentServer(backend.util.service.AppProcess):
    def run(self):
        server_app = starlette.middleware.cors.CORSMiddleware(
            app=app,
            allow_origins=settings.config.backend_cors_allow_origins,
            allow_credentials=True,
            allow_methods=["*"],  # Allows all methods
            allow_headers=["*"],  # Allows all headers
        )
        log_config = dict(uvicorn.config.LOGGING_CONFIG)
        log_config["loggers"]["uvicorn"] = {"handlers": []}
        log_config["loggers"]["uvicorn.error"] = {"handlers": []}
        log_config["loggers"]["uvicorn.access"] = {"handlers": []}
        uvicorn.run(
            server_app,
            host=backend.util.settings.Config().agent_api_host,
            port=backend.util.settings.Config().agent_api_port,
            log_config=log_config,
        )

    @staticmethod
    async def test_execute_graph(
        graph_id: str,
        user_id: str,
        graph_version: Optional[int] = None,
        node_input: Optional[dict[str, Any]] = None,
    ):
        return backend.server.routers.v1.execute_graph(
            user_id=user_id,
            graph_id=graph_id,
            graph_version=graph_version,
            node_input=node_input or {},
        )

    @staticmethod

Review comment (refactor):
Can't we move this replicated logic to configure_logging or other shared helper?
This kind of hinting that we also need this on all services/processes. we have notification service, scheduler, database manager, execution manager, but I guess this might have been somehow covered by AppService?

Code after:
)

app.include_router(
    backend.server.routers.postmark.postmark.router,
    tags=["v1", "email"],
    prefix="/api/email",
)

app.mount("/external-api", external_app)


@app.get(path="/health", tags=["health"], dependencies=[])
async def health():
    return {"status": "healthy"}


class AgentServer(backend.util.service.AppProcess):
    def run(self):
        server_app = starlette.middleware.cors.CORSMiddleware(
            app=app,
            allow_origins=settings.config.backend_cors_allow_origins,
            allow_credentials=True,
            allow_methods=["*"],  # Allows all methods
            allow_headers=["*"],  # Allows all headers
        )
        uvicorn.run(
            server_app,
            host=backend.util.settings.Config().agent_api_host,
            port=backend.util.settings.Config().agent_api_port,
            log_config=generate_uvicorn_config(),
        )

    @staticmethod
    async def test_execute_graph(
        graph_id: str,
        user_id: str,
        graph_version: Optional[int] = None,
        node_input: Optional[dict[str, Any]] = None,
    ):
        return backend.server.routers.v1.execute_graph(
            user_id=user_id,
            graph_id=graph_id,
            graph_version=graph_version,
            node_input=node_input or {},
        )

    @staticmethod
    async def test_get_graph(
        graph_id: str,
        graph_version: int,
        user_id: str,