Skip to content

Conversation

@MehakBindra
Copy link
Contributor

@MehakBindra MehakBindra commented Oct 23, 2025

Tested with code like (check running on and activities received on port 8000 )

def make_server(app: FastAPI) -> uvicorn.Server:
    config = uvicorn.Config(
        app=app,
        host="0.0.0.0",
        port=8000,
        log_level="debug",
    )
    return uvicorn.Server(config)


app = App(
    plugins=[
        DevToolsPlugin(),
        HttpPlugin(app_id=None, server_factory=make_server),
    ]
)

Copilot AI review requested due to automatic review settings October 23, 2025 22:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for custom server configuration in the HTTPPlugin by introducing a server_factory parameter. This enables users to provide their own pre-configured uvicorn server with custom options like SSL certificates, custom logging, or other server-level configurations.

Key Changes:

  • Added optional server_factory parameter to HTTPPlugin constructor
  • Modified startup logic to use custom server when provided, with port conflict detection
  • Added documentation for the new parameter

try:
config = uvicorn.Config(app=self.app, host="0.0.0.0", port=port, log_level="info")
self._server = uvicorn.Server(config)
if self._server and self._server.config.port != self._port:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may want to move this port check into the constructor, so it fails earlier

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not throwing an error for this, just a warning to say the port being used is from this builder fn and not the one provided by app.
Also the port is not available then I think, because it can be provided via app.start(port=..) too right

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah thats true, it comes from the event itself- instead of saying 'plugin had requested' can we say the plugin start event?

app_id: Optional[str],
logger: Optional[Logger] = None,
skip_auth: bool = False,
server_factory: Optional[Callable[[FastAPI], uvicorn.Server]] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be more generic? Instead of FastAPI, can it just be ASGIApplication, and instead of uvicorn.Server, it should be whatever server is being used right? The whole point of this effort is that something other than uvicorn.Server should be returnable?

One option is to make this piece generic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants