-
-
Notifications
You must be signed in to change notification settings - Fork 51
Fix BASE_URL support #760
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
Closed
Closed
Fix BASE_URL support #760
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4ed2bd5 to
80d5c33
Compare
Previously BASE_URL only applied when base_url was empty in the database, leaving users with incorrect values unable to recover without manual database editing. Now BASE_URL environment variable always overrides the database value when set, providing a recovery path for misconfigured deployments.
Flask routes are registered at paths like /setup, but when BASE_URL is configured, requests arrive as /huntarr/setup. Added BaseURLMiddleware to strip the BASE_URL prefix from request paths before Flask routing occurs, allowing routes to be found correctly. Also normalized BASE_URL handling with helper functions to consistently handle edge cases like '/', whitespace, and multiple slashes.
Updated all redirect calls to prepend BASE_URL when redirecting to setup, login, and user pages. This ensures redirects work correctly when the application is deployed under a reverse proxy subpath. Fixes redirect loops that occurred when BASE_URL was configured.
Updated cycle countdown timer to use window.HUNTARR_BASE_URL when constructing API URLs, ensuring API calls work correctly when BASE_URL is configured for reverse proxy deployments.
7764c1b to
8276422
Compare
Signed-off-by: Jared Ledvina <jared@techsmix.net>
Signed-off-by: Jared Ledvina <jared@techsmix.net>
This was referenced Dec 24, 2025
Admin9705
added a commit
that referenced
this pull request
Jan 22, 2026
Core Changes: - Add WSGI middleware to strip BASE_URL prefix before Flask routing - Centralize base URL logic with get_base_url_path() helper - Update environment variable to always override DB settings (Docker best practice) - Improve path checking to use startswith() instead of 'in' operator - Update all redirects to use centralized base URL helper Backend Updates: - web_server.py: Add BaseURLMiddleware class for proper subpath handling - auth.py: Add get_base_url_path() helper, update authenticate_request() path checks - routes/common.py: Simplify redirect logic using base URL helper - plex_auth_routes.py: Update Plex callback redirects - settings_manager.py: Environment variable now always overrides DB setting Frontend Updates: - cycle-countdown.js: Use window.HUNTARR_BASE_URL for API calls - Already has frontend injection in templates (index.html, login.html, etc.) Architecture: - WSGI middleware strips /huntarr from /huntarr/api/logs → Flask sees /api/logs - Industry-standard pattern for subpath deployments - No route modifications needed - middleware handles everything - Environment variable precedence follows Docker/k8s best practices Fixes: #649, #732 Related: #130 Testing: - Standard Docker deployment (no BASE_URL) - Docker with BASE_URL=/huntarr - BASE_URL changes via env var - All redirects and API calls Refinements over original PR: - Changed 'in' operator to startswith() for more precise path matching - Consistent base URL helper used throughout codebase - Simplified redirect logic (removed repetitive inline base URL logic)
Contributor
|
Patched via - https://github.com/plexguide/Huntarr.io/releases/tag/8.2.17 - thanks again! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves #649, #732
Related to #130
This PR updates the overall logic around the
BASE_URLparameter. I've built Hunter off this branch and am running it. So far, it looks like this will completely restore the BASE_URL support so that it works as intended. See the commits for a break down for each of the bits.I've locally tested this change with
BASE_URLset tohuntarr, changing tohuntarrtesting, and then to''and confirmed that in all 3 cases it works and adjusts the base path each time. I also dropped the env variable and confirmed that the DB saved the latest config and used that appropriately.