Skip to content

Commit 6773846

Browse files
committed
docs: add subpath compatibility guide and anti-patterns to prevent URL breaks
1 parent 8560577 commit 6773846

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

.github/listen.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,119 @@ function fetchData() {
253253
}
254254
```
255255

256+
## 🚨 CRITICAL: Subpath Compatibility Lessons (PR #527)
257+
258+
**PROBLEM:** Huntarr broke when deployed in subdirectories (e.g., `domain.com/huntarr/`) due to absolute URL references that failed in subpath environments.
259+
260+
**SYMPTOMS:**
261+
- Application works at root domain (`domain.com`) but fails in subdirectories
262+
- Navigation redirects break (redirect to wrong URLs)
263+
- CSS/JS resources fail to load
264+
- API calls return 404 errors
265+
- Setup process gets stuck
266+
267+
### 🔧 Critical Fix Patterns from PR #527
268+
269+
#### 1. JavaScript Navigation URLs - HIGH PRIORITY
270+
**❌ BROKEN:**
271+
```javascript
272+
// Absolute URLs break in subpaths
273+
window.location.href = '/'; // Redirects to domain.com instead of domain.com/huntarr/
274+
```
275+
276+
**✅ FIXED:**
277+
```javascript
278+
// Relative URLs work in all environments
279+
window.location.href = './'; // Correctly redirects to current subpath
280+
```
281+
282+
**Files to Check:**
283+
- `/frontend/static/js/new-main.js` - Settings save redirects
284+
- `/frontend/templates/setup.html` - Setup completion redirects
285+
- Any JavaScript with `window.location.href = '/'`
286+
287+
#### 2. CSS Resource Loading - HIGH PRIORITY
288+
**❌ BROKEN:**
289+
```html
290+
<!-- Multiple CSS files with incorrect names -->
291+
<link rel="stylesheet" href="./static/css/variables.css">
292+
<link rel="stylesheet" href="./static/css/styles.css">
293+
```
294+
295+
**✅ FIXED:**
296+
```html
297+
<!-- Single consolidated CSS file -->
298+
<link rel="stylesheet" href="./static/css/style.css">
299+
```
300+
301+
**Files to Check:**
302+
- `/frontend/templates/base.html` - Main CSS references
303+
- `/frontend/templates/components/head.html` - Head CSS includes
304+
- Any template with CSS `<link>` tags
305+
306+
#### 3. API Endpoint URLs
307+
**✅ GOOD PATTERN (Already implemented):**
308+
```javascript
309+
// Relative API calls work in subpaths
310+
fetch('./api/sleep.json') // ✅ Works
311+
fetch('/api/sleep.json') // ❌ Breaks in subpaths
312+
```
313+
314+
### 🔍 Subpath Testing Checklist
315+
316+
**MANDATORY before any frontend changes:**
317+
- [ ] Test navigation from every page (all redirects work)
318+
- [ ] Test CSS/JS resources load correctly
319+
- [ ] Test API calls work from all pages
320+
- [ ] Test setup process completion
321+
- [ ] Test authentication flow redirects
322+
- [ ] Test with reverse proxy configuration: `domain.com/huntarr/`
323+
324+
### 🚨 Subpath Anti-Patterns to AVOID
325+
326+
1. **❌ NEVER use absolute URLs in JavaScript:**
327+
```javascript
328+
window.location.href = '/'; // BREAKS subpaths
329+
window.location.href = '/settings'; // BREAKS subpaths
330+
fetch('/api/endpoint'); // BREAKS subpaths
331+
```
332+
333+
2. **❌ NEVER hardcode root paths in templates:**
334+
```html
335+
<link href="/static/css/style.css"> <!-- BREAKS subpaths -->
336+
<script src="/static/js/app.js"> <!-- BREAKS subpaths -->
337+
```
338+
339+
3. **❌ NEVER assume root deployment:**
340+
```python
341+
redirect('/') # BREAKS in Flask routes with subpaths
342+
```
343+
344+
### 🎯 Subpath Prevention Strategy
345+
346+
**Before committing any frontend changes:**
347+
348+
1. **Search for absolute URL patterns:**
349+
```bash
350+
grep -r "href=\"/" frontend/
351+
grep -r "src=\"/" frontend/
352+
grep -r "window.location.href = '/" frontend/
353+
grep -r "fetch('/" frontend/
354+
```
355+
356+
2. **Test deployment scenarios:**
357+
- Root deployment: `http://localhost:9705/`
358+
- Subpath deployment: `http://localhost:9705/huntarr/`
359+
- Reverse proxy: `https://domain.com/huntarr/`
360+
361+
3. **Verify all navigation works:**
362+
- Home → Settings → Home
363+
- Setup flow completion
364+
- Authentication redirects
365+
- Error page redirects
366+
367+
**LESSON LEARNED:** Subpath compatibility issues are SILENT FAILURES that only surface in production reverse proxy environments. Always test with subpath configurations before deploying.
368+
256369
## 🔧 Development Workflows
257370
258371
### Environment Testing Checklist

0 commit comments

Comments
 (0)