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

Adding basepath to the config #6963

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Adding basepath to the config #6963

wants to merge 5 commits into from

Conversation

ewassef
Copy link

@ewassef ewassef commented Dec 18, 2024

This will allow the aspire app to handle running behind a reverse proxy such as a k8s ingress on a subpath #4159
#4528
#5134

Description

Added a new dashboard base path option, integrated it into the Dashboard Option, validated and replaced all areas that are creating the links

Fixes # (issue)

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • [x ] No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • [] No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?
Microsoft Reviewers: Open in CodeFlow

This will allow the aspire app to handle running behind a reverse proxy such as a k8s ingress on a subpath
dotnet#4159
dotnet#4528
dotnet#5134
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Dec 18, 2024
Copy link
Member

@adamint adamint left a comment

Choose a reason for hiding this comment

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

Please add test coverage in ValidateDashboardOptions.

url = QueryHelpers.AddQueryString(url, "language", language);
url = QueryHelpers.AddQueryString(url, "redirectUrl", redirectUrl);

return url;
}

internal static void SetBasePath(string pathBase) => BasePath = pathBase;
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem like an optimal way to update BasePath to me. If DashboardUrls is going to store this state, it should be turned into a service and injected.

Copy link
Author

Choose a reason for hiding this comment

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

I am following the SetLanguageUrl method above

Copy link
Member

Choose a reason for hiding this comment

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

It’s different, as SetLanguageUrl does not set state. It only returns the url for the set language url path.

Copy link
Author

Choose a reason for hiding this comment

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

OK. Is this something that will block the feature from being accepted?

Copy link
Member

Choose a reason for hiding this comment

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

See the comment below, DashboardUrls shouldn't be changed at all

@adamint
Copy link
Member

adamint commented Dec 19, 2024

@JamesNK for review

@ewassef
Copy link
Author

ewassef commented Dec 23, 2024

Please add test coverage in ValidateDashboardOptions.

Tests added

rerunning the PR checks
@davidfowl
Copy link
Member

The options changes look fine, but this is a one liner in middleware https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.usepathbaseextensions.usepathbase?view=aspnetcore-9.0.

You can undo all of the other changes you made.

@ewassef
Copy link
Author

ewassef commented Dec 26, 2024

The options changes look fine, but this is a one liner in middleware https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.usepathbaseextensions.usepathbase?view=aspnetcore-9.0.

You can undo all of the other changes you made.

@davidfowl , I'm afraid I do not follow. I am using that method in the middleware, but everything else is to handle the options and also the way we are generating the link in the blazor app. The links seem to be string interpolation from the base before

@adamint
Copy link
Member

adamint commented Dec 26, 2024

The options changes look fine, but this is a one liner in middleware https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.usepathbaseextensions.usepathbase?view=aspnetcore-9.0.
You can undo all of the other changes you made.

@davidfowl , I'm afraid I do not follow. I am using that method in the middleware, but everything else is to handle the options and also the way we are generating the link in the blazor app. The links seem to be string interpolation from the base before

I see what fowler means now. We don't need to store path base inside DashboardUrls. You do however need to provide a <base> tag in blazor since the base path is changed.

the way we are generating the link

The path base is provided in the dashboard options already. You can use that when writing out the dashboard url.

@davidfowl
Copy link
Member

davidfowl commented Dec 26, 2024

There should be a single call to the UsePathBase middleware in the code base. You can undo all of the other changes that were made to prepend the path base into various places in the application.

@adamint
Copy link
Member

adamint commented Dec 27, 2024

There should be a single call to the UsePathBase middleware in the code base. You can undo all of the other changes that were made to prepend the path base into various places in the application.

We need to change the blazor client-side path base as well.

@davidfowl
Copy link
Member

davidfowl commented Dec 28, 2024

Why? Also UsePathBase should be the first middleware (order matters). We should be able to remove the prefix in UseErrorHandler as well.

@JamesNK
Copy link
Member

JamesNK commented Dec 28, 2024

Is blazor loading something from a rooted path? Eg /blazor.

Can it be changed to a relative path? ./blazor

@JamesNK
Copy link
Member

JamesNK commented Dec 28, 2024

https://learn.microsoft.com/en-nz/aspnet/core/blazor/host-and-deploy/?view=aspnetcore-8.0&tabs=visual-studio#app-base-path

I don’t know the right thing to do (haven’t read docs) but there are a lot of docs on this issue. Find out what is best with blazor server in this situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants