Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using Aspire locally always use the same port, without proxying #287

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

dluc
Copy link
Contributor

@dluc dluc commented Dec 12, 2024

Aspire by default randomizes ports, however this means that cookies from a previous session most likely don't work, in which case the workbench show the set of initial banners and asks to sign in, every time.

The PR changes this behavior on localhost, to always use port 4000 (assuming it's free), similarly to how the app runs without Aspire.

@tommasodotNET
Copy link
Contributor

To achieve this, we can keep the Aspire proxy and simply remove the env: PORT param, passing port: 4000 instead. This way, the app will run on localhost:4000 and will be proxied by Aspire. Cookies should work.

@dluc
Copy link
Contributor Author

dluc commented Dec 12, 2024

To achieve this, we can keep the Aspire proxy and simply remove the env: PORT param, passing port: 4000 instead. This way, the app will run on localhost:4000 and will be proxied by Aspire. Cookies should work.

just wondering and ignoring port forwarding in the cloud: when working locally is there any reason to use two ports and the proxy? For a team spending most of the time developing on localhost, and always working with port 4000, it seems unnecessary. Thoughts?

By the way, I could not understand the use case of env: PORT when working locally. What does it do? I tried setting the env var in launchSettings, but it was not being used.

@tommasodotNET
Copy link
Contributor

To achieve this, we can keep the Aspire proxy and simply remove the env: PORT param, passing port: 4000 instead. This way, the app will run on localhost:4000 and will be proxied by Aspire. Cookies should work.

just wondering and ignoring port forwarding in the cloud: when working locally is there any reason to use two ports and the proxy? For a team spending most of the time developing on localhost, and always working with port 4000, it seems unnecessary. Thoughts?

By the way, I could not understand the use case of env: PORT when working locally. What does it do? I tried setting the env var in launchSettings, but it was not being used.

Docs states that:
.NET Aspire automatically launches a proxy for each service binding you add to your app, and assigns a port for the proxy to listen on. The proxy then forwards the requests to the port that your app listens on, which might be different from the proxy port. This way, you can avoid port conflicts and access your app and services using consistent and predictable URLs.

Nonetheless, if you think we don't need the proxy, we can get rid of that.

@dluc
Copy link
Contributor Author

dluc commented Dec 13, 2024

To achieve this, we can keep the Aspire proxy and simply remove the env: PORT param, passing port: 4000 instead. This way, the app will run on localhost:4000 and will be proxied by Aspire. Cookies should work.

just wondering and ignoring port forwarding in the cloud: when working locally is there any reason to use two ports and the proxy? For a team spending most of the time developing on localhost, and always working with port 4000, it seems unnecessary. Thoughts?
By the way, I could not understand the use case of env: PORT when working locally. What does it do? I tried setting the env var in launchSettings, but it was not being used.

Docs states that: .NET Aspire automatically launches a proxy for each service binding you add to your app, and assigns a port for the proxy to listen on. The proxy then forwards the requests to the port that your app listens on, which might be different from the proxy port. This way, you can avoid port conflicts and access your app and services using consistent and predictable URLs.

Nonetheless, if you think we don't need the proxy, we can get rid of that.

unfortunately the random port is an issue with cookies/localstore, see PR description.

@dluc dluc merged commit 1b2de09 into microsoft:main Dec 13, 2024
1 check passed
@dluc dluc deleted the appport branch December 13, 2024 16:12
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.

2 participants