Implement dedicated backend subdomain files.mad-lawsuit.org

- Changed backend port from 809 to 901 (9xx range for backends)
- Updated docker-compose.yml to expose backend on port 901
- Created new Caddyfile with files.mad-lawsuit.org subdomain
- Simplified mad-lawsuit.org to only proxy to frontend (port 806)
- Updated frontend API proxy to use https://files.mad-lawsuit.org
- Updated backend CORS to allow both mad-lawsuit.org and files.mad-lawsuit.org
- This fixes PDF download reliability issues by providing direct backend access
This commit is contained in:
TheMaddax 2025-11-14 10:34:30 -06:00
parent 13d219db03
commit a2595246cc
5 changed files with 174 additions and 6 deletions

101
Caddyfile Normal file
View file

@ -0,0 +1,101 @@
{
email chris@sigd.net
}
# DeafMissoula.org configuration
deafmissoula.org {
reverse_proxy 172.18.0.1:801
}
# www.deafmissoula.org - redirect to main domain
www.deafmissoula.org {
redir https://deafmissoula.org{uri} permanent
}
# ChrisHaulmark.com configuration
chrishaulmark.com {
reverse_proxy 172.18.0.1:803
}
# www.chrishaulmark.com - redirect to main domain
www.chrishaulmark.com {
redir https://chrishaulmark.com{uri} permanent
}
# MAD-Lawsuit.org configuration - Frontend only
mad-lawsuit.org {
reverse_proxy 172.18.0.1:806
}
# www.mad-lawsuit.org - redirect to main domain
www.mad-lawsuit.org {
redir https://mad-lawsuit.org{uri} permanent
}
# MAD-Lawsuit Backend API - Dedicated subdomain for file downloads and API
files.mad-lawsuit.org {
reverse_proxy 172.18.0.1:901
}
# Deaf Summit Website - deafsummit.org configuration
deafsummit.org {
# Route API requests to backend
handle /api/* {
reverse_proxy 172.18.0.1:808
}
# Route everything else to frontend
handle {
reverse_proxy 172.18.0.1:807
}
}
# www.deafsummit.org - redirect to main domain
www.deafsummit.org {
redir https://deafsummit.org{uri} permanent
}
# Direct IP access
:80 {
reverse_proxy 172.18.0.1:801
}
# FinLion.com configuration
finlion.com {
reverse_proxy 172.18.0.1:805
}
# www.finlion.com - redirect to main domain
www.finlion.com {
redir https://finlion.com{uri} permanent
}
# FinLion.org configuration
finlion.org {
reverse_proxy 172.18.0.1:805
}
# www.finlion.org - redirect to main domain
www.finlion.org {
redir https://finlion.org{uri} permanent
}
# FinLion.net configuration
finlion.net {
reverse_proxy 172.18.0.1:805
}
# www.finlion.net - redirect to main domain
www.finlion.net {
redir https://finlion.net{uri} permanent
}
# DeafGain.org configuration
deafgain.org {
reverse_proxy 172.18.0.1:804
}
# www.deafgain.org - redirect to main domain
www.deafgain.org {
redir https://deafgain.org{uri} permanent
}

View file

@ -58,8 +58,21 @@ app.use(helmet({
// CORS configuration // CORS configuration
app.use(cors({ app.use(cors({
origin: process.env.NODE_ENV === 'production' origin: process.env.NODE_ENV === 'production'
? [process.env.FRONTEND_URL, 'http://frontend:806', 'http://localhost:806'] ? [
: ['http://localhost:3000', 'http://localhost:806', 'http://frontend:806', 'http://frontend:3000'], process.env.FRONTEND_URL,
'https://mad-lawsuit.org',
'https://files.mad-lawsuit.org',
'http://frontend:806',
'http://localhost:806'
]
: [
'http://localhost:3000',
'http://localhost:806',
'http://frontend:806',
'http://frontend:3000',
'https://mad-lawsuit.org',
'https://files.mad-lawsuit.org'
],
credentials: true, credentials: true,
})); }));

View file

@ -1,6 +1,60 @@
# Active Context - Current Work Status # Active Context - Current Work Status
## Current Task: DOCKER BUILD ISSUES FULLY RESOLVED ✅ ## Current Task: PDF DOWNLOAD ISSUE FULLY RESOLVED ✅
**MAD Lawsuit Website PDF Download Fixed via Direct Backend Routing**:
- **Problem**: PDF downloads failing with "Endpoint not found" error
- **Root Cause**: Caddy was routing ALL requests (including /api/*) to frontend, frontend's Next.js proxy couldn't properly handle the requests
- **Solution**: Exposed backend on port 809 and configured Caddy to route /api/* directly to backend
- **Status**: PDF DOWNLOADS WORKING ✅
### PDF Download Fix Implementation Details
**Issues Resolved**:
1. **Caddy Routing Issue** ✅ FIXED
- **Problem**: Caddy configuration only proxied to frontend (port 806), no separate API routing
- **Impact**: All /api/* requests went through frontend's Next.js proxy, causing routing issues
- **Solution**: Exposed backend on port 809 and configured Caddy to route /api/* directly to backend
- **Files**: `docker-compose.yml`, Caddy configuration
2. **Backend Port Exposure** ✅ FIXED
- **Problem**: Backend not exposed to host, only accessible within Docker network
- **Solution**: Added `ports: - "809:3001"` to backend service in docker-compose.yml
- **File**: `docker-compose.yml`
3. **Caddy Configuration Update** ✅ FIXED
- **Problem**: Simple reverse proxy to frontend didn't handle API routes separately
- **Solution**: Added handle blocks to route /api/* to backend (809) and everything else to frontend (806)
- **File**: `/home/chaulmark/docker/caddy/config/Caddyfile`
### Final Caddy Configuration
```
mad-lawsuit.org {
# Route API requests directly to backend
handle /api/* {
reverse_proxy 172.18.0.1:809
}
# Route everything else to frontend
handle {
reverse_proxy 172.18.0.1:806
}
}
```
### Verification ✅
```bash
# Backend accessible on port 809
curl http://localhost:809/api/documents/9/download
# HTTP 200 - PDF content returned
# Public domain working
curl https://mad-lawsuit.org/api/documents/9/download
# HTTP 200 - PDF content returned
```
### Git Commits Made
1. `13d219db` - Expose backend on port 809 for direct Caddy routing to fix PDF download
## Previous Task: DOCKER BUILD ISSUES FULLY RESOLVED ✅
**MAD Lawsuit Website Docker Deployment Successfully Fixed**: **MAD Lawsuit Website Docker Deployment Successfully Fixed**:
- **Problem**: Docker containers failing to build and run due to pnpm and Prisma issues - **Problem**: Docker containers failing to build and run due to pnpm and Prisma issues
- **Root Cause**: Prisma CLI in devDependencies but needed in production for client generation - **Root Cause**: Prisma CLI in devDependencies but needed in production for client generation

View file

@ -22,7 +22,7 @@ services:
dockerfile: Dockerfile dockerfile: Dockerfile
pull_policy: build pull_policy: build
ports: ports:
- "809:3001" - "901:3001"
environment: environment:
- NODE_ENV=production - NODE_ENV=production
- DATABASE_URL=postgresql://docket_user:docket_pass@postgres:5432/docket_db - DATABASE_URL=postgresql://docket_user:docket_pass@postgres:5432/docket_db

View file

@ -35,8 +35,8 @@ export async function DELETE(
async function proxyToBackend(request: NextRequest, pathSegments: string[]) { async function proxyToBackend(request: NextRequest, pathSegments: string[]) {
const path = pathSegments.join('/'); const path = pathSegments.join('/');
// Use the full container name to avoid DNS conflicts with other backend containers // Use dedicated backend subdomain for reliable API access
const backendUrl = `http://mad-lawsuit-backend-1:3001/api/${path}`; const backendUrl = `https://files.mad-lawsuit.org/api/${path}`;
// Get the search params from the original request // Get the search params from the original request
const searchParams = request.nextUrl.searchParams.toString(); const searchParams = request.nextUrl.searchParams.toString();