Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat: Support configurable base path for server #714
feat: Support configurable base path for server #714
Changes from 1 commit
453f0d2
cd80c43
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the root of the server is hit and we have a base path configured redirect to that base path for convenience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested this locally with an nginx reverse proxy (configuration below) but encountered an issue when accessing via the proxy path
http://localhost/dagu/
. It seems the path prefix check might be the cause. The following code, however, works as expected:Would you mind taking a look when you have a chance?
Test setup
~/.dagu/admin.cfg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is the trailing slash. I was only testing with
/dagu
and missed this case.I have made the BasePath more robust
prefixChecker
to strip the prefix first, then do the strings.HasPrefix check in a HandlerFunc to not have to worry about the prefix.I tested with
/
/dagu
/dagu/
/dagu/foo
I believe this should be good.
I have pushed up the fix as a
!fixup
commit to make it easier to review. This can be "squashed" when merging or I can squash it before this is ready to merge.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better solution to
path.Join
here? It doesn't feel robust.It really feels like
/api
should be a handler which is hung off ofhttp.StripPrefix(basePath, next)
such that any route registered under it would be handled by/api
I wasn't sure of the consequences of such a change however, so I just updated the string comparison.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #714 (comment) this has been improved to not rely on path.join for this prefix check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http.StripPrefix
seemed like the cleanest way to allow all existing routes to work as before.This is my first time writing Go so if there's a more idiomatic way of doing this let me know!