Skip to content

Add configuration option for application root URL#114

Merged
loic-sharma merged 4 commits intoloic-sharma:masterfrom
daniel-lerch:master
Nov 11, 2018
Merged

Add configuration option for application root URL#114
loic-sharma merged 4 commits intoloic-sharma:masterfrom
daniel-lerch:master

Conversation

@daniel-lerch
Copy link
Contributor

What does this PR do?

This pull request adds the setting PathBase to the BaGet configuration and applies this setting on startup. The PathBase option allows an ASP.NET Core application to run under a different root URL than it was designed for.

Motivation

I want to operate a BaGet server with a URL like https://example.com/baget and reach the API index at https://example.com/baget/v3/index.json. With this change I don't have to write complex rewrite rules for this scenario which might not work at all.

Additional Notes

Deal with path base and proxies that change the request path on Microsoft Docs

}
}

app.UsePathBase(Configuration.Get<BaGetOptions>().PathBase);
Copy link
Owner

Choose a reason for hiding this comment

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

Does this throw if PathBase is null? If it does, please add a null check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This option does not throw on null.

@loic-sharma
Copy link
Owner

Looks great! I left some minor comments, I'll merge once you've addressed them :)

@daniel-lerch
Copy link
Contributor Author

This PR will take longer than expected. I experienced problems with the configuration as some URLs are kind of hard-coded and are not adjusted by changing the PathBase. I'll write another comment when this is fixed.

@loic-sharma
Copy link
Owner

Sounds good. Let me know if you have any questions

@daniel-lerch
Copy link
Contributor Author

The API can now be configured to run under a different PathBase. I only had to change the manual URLs generation.

For the web UI it is not that easy to configure the base path as the site is served as static content. Two ways to resolve this problem:

  1. We could change the links to Baget.UI.xyz instead of /Baget.UI.xyz
  2. We create a new controller for the web UI which replaces these variables and serves the files. With a memory cache we won't loose performance but I don't want to implement this major change myself.

@loic-sharma
Copy link
Owner

loic-sharma commented Nov 8, 2018

Ah I see. Today, the frontend's API endpoints are hardcoded in the code base. My recommendation for you:

  1. Make a temporary fork of BaGet
  2. Update the URIs in the frontend:
    a. DisplayPackage.tsx#L55
    b. DisplayPackage.tsx#L112
    c. SearchResults.tsx#L71
    d. SearchResults.tsx#L72
  3. Build the frontend using these instructions

This is a short-term solution that should let you host BaGet in a different root URL. I'd like to make the backend's endpoint configurable at build time, but I will be investing in other areas first (unit test coverage and an actual release process). Please let me know if you run into any issues!

@daniel-lerch
Copy link
Contributor Author

Is there anything missing to merge this PR or do you want to wait until the frontend will work with a different root URL?

@loic-sharma
Copy link
Owner

loic-sharma commented Nov 10, 2018

Your changes look good! I moved some things around after you opened this pull request - would you mind reapplying your changes on the latest master? I'll go ahead and merge after :)

@daniel-lerch
Copy link
Contributor Author

I just merged your changes into my fork.

@loic-sharma loic-sharma merged commit 7fac8a4 into loic-sharma:master Nov 11, 2018
@loic-sharma
Copy link
Owner

Thank you :)

@cn4hub
Copy link

cn4hub commented Feb 19, 2019

Hello,

I'm trying to use this, but it is not working right now.

appsettings.json:
{ [...] "PathBase": "/nuget", [...] }
Can u help me to understand, how I've to set this option?
Thx in advance.

@daniel-lerch
Copy link
Contributor Author

The PathBase option only affects the API which is served by ASP.NET Core. You should be able to access http://localhost:5000/nuget/v3/index.json. Visual Studio should work with this path base as expected.

However, the Web UI does not work as mentioned above.

@cn4hub
Copy link

cn4hub commented Feb 19, 2019

Is there any solution for having BaGet incl. UI behind a proxy? I got the feeling I'm missing something obvious here.
Thx for ur help.

@daniel-lerch
Copy link
Contributor Author

There is currently no way to run BaGet's web UI with a different root URL.

@loic-sharma recommend to change the hard-coded URLs in one's own fork (see above).

@loic-sharma
Copy link
Owner

loic-sharma commented Feb 19, 2019

I haven’t tested this, but you should be able to add the homepage setting to the package.json file to support your need. See: https://facebook.github.io/create-react-app/docs/deployment

@cn4hub
Copy link

cn4hub commented Feb 21, 2019

After trying different things imcluding homepage, basename etc. I've to say, that i'm not making any progress. I need to take a look at this topic again. Thank you for your effort and your help so far.

0xced pushed a commit to 0xced/BaGet that referenced this pull request Mar 30, 2025
…irror (loic-sharma#114)

* Implementation, docs, and basic tests

* Split mirror options file into file for each class

* Restructure documentation for mirror

* Update mirror auth tests

adds missing verify
share common setup

* Revert splitting mirror doc into separate page

* Fix incorrent validation condition

---------

Signed-off-by: Marlon Regenhardt <marlon.r@hotmail.de>
Co-authored-by: Marlon Regenhardt <marlon.r@hotmail.de>
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.

3 participants