Skip to content

Retrieve the port from the server #3949

Closed

Description

@Isakdl

Problem to Solve

The real port in use cannot be retrieved from the server instance. The one that is accessible today is taken from the constructor input, but if I set the port to 0, which means take any port that is available, the real port in use will be different. That port is today not accessible from the outside of the start method (that lives in the framework).

Proposal

Modify the server getter of port to return the real port, something like this:

Which would return the real port if available, otherwise the input port.

// server.dart
int get port => _ioServer?.port ?? _port;

The ports would also need to be accessible from the test framework, as the server object is hidden in there. Perhaps this would warrant another test method? E.g. withRelic instead of withServerpod, for example.

Use Case

In the test framework, the port is set to 0 by default, which is a very good default, as that enables concurrent tests. But if I want to make network calls to any of the servers api, insights, web, I'm not able to do that as I cannot retrieve the port.

In my specific case I would like to make a network request to the webserver.

Alternatives

Hard-code the port, but then you lose the ability to run concurrently.

Additional context

No response

How experienced are you with this library?

Expert - Experienced and comfortable with using this library in complex projects

Are you interested in working on a PR for this?

  • I want to work on this

Activity

  1. added
    enhancement
    on Sep 2, 2025
  2. moved this from Inbox 📫 to Backlog 🗂️ in Serverpod Frameworkson Sep 4, 2025
  3. moved this from Backlog 🗂️ to Next Up 🎯 in Serverpod Frameworkson Sep 4, 2025
  4. added
    area: web server
    area: test framework
    on Sep 4, 2025
  5. christerswahn commented on Sep 5, 2025

    @christerswahn
    Contributor

    This should be already fixed in PR #3775 . Does it not work?

  6. Isakdl commented on Sep 5, 2025

    @Isakdl
    CollaboratorAuthor

    You are right! But it is only for the web server! So in fact my bug report is slightly wrong, we get the real port for the web server, but not the others!

  7. moved this from Next Up 🎯 to Contributor In Progress 👩‍💻 in Serverpod Frameworkson Sep 30, 2025
  8. moved this from Contributor In Progress 👩‍💻 to Done 🚀 in Serverpod Frameworkson Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: test frameworkarea: web serverenhancement

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions