Skip to content

Conversation

@jaredledvina
Copy link

@jaredledvina jaredledvina commented Dec 6, 2025

Resolves #649, #732
Related to #130

This PR updates the overall logic around the BASE_URL parameter. 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_URL set to huntarr, changing to huntarrtesting, 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.

@jaredledvina jaredledvina force-pushed the fix/base-url-issue-649 branch from 4ed2bd5 to 80d5c33 Compare December 6, 2025 05:37
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.
@jaredledvina jaredledvina force-pushed the fix/base-url-issue-649 branch from 7764c1b to 8276422 Compare December 6, 2025 17:50
@jaredledvina jaredledvina changed the title Fix base_url configuration Fix BASE_URL support Dec 6, 2025
@jaredledvina jaredledvina marked this pull request as ready for review December 7, 2025 01:12
Signed-off-by: Jared Ledvina <jared@techsmix.net>
Signed-off-by: Jared Ledvina <jared@techsmix.net>
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)
@Admin9705
Copy link
Contributor

Patched via - https://github.com/plexguide/Huntarr.io/releases/tag/8.2.17 - thanks again!

@Admin9705 Admin9705 closed this Jan 22, 2026
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.

Configuring the base_url seems to break the install

2 participants