# GlitchTip / Sentry DSN Path-Prefix Quirk

## The Problem

When GlitchTip (Sentry-compatible) is hosted behind an nginx path prefix like `/glitchtip/`, the Sentry SDK's DSN parser **rejects** the multi-segment path.

**DSN format Sentry expects:**
```
https://<public_key>@<host>/<project_id>
```
Single path segment only. `/1` in the path is the project ID (a number).

**What doesn't work:**
```
https://<key>@host/glitchtip/1
```
The Sentry SDK v10+ DSN parser throws `Invalid Sentry Dsn` because `glitchtip/1` is two path segments, not one.

## The Fix

### 1. Change the DSN in env file

```
VITE_GLITCHTIP_DSN=https://<key>@host/1
```
Remove `/glitchtip` from the DSN path. Keep only the project ID.

### 2. Add nginx location for bare project-ID paths

The original `/glitchtip/` location remains for backward compatibility. Add a new regex location that matches `/<digits>/api/` and `/digits/store/` and proxies to GlitchTip:

```nginx
# In the server block:
location /glitchtip/ {
    rewrite ^/glitchtip/[0-9]+/(api/.*)$ /$1 break;
    rewrite ^/glitchtip/[0-9]+/(store/.*)$ /api/1/$1 break;
    rewrite ^/glitchtip/(.*)$ /$1 break;
    proxy_pass http://127.0.0.1:8001;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_buffering off;
}

# Bare project-ID path (for Sentry DSN compat)
location ~ ^/([0-9]+)/(api|store)/(.*)$ {
    rewrite ^/([0-9]+)/api/(.*)$ /api/$1/$2 break;
    rewrite ^/([0-9]+)/store/(.*)$ /api/$1/$2 break;
    proxy_pass http://127.0.0.1:8001;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_buffering off;
}
```

### 3. Rebuild frontend

```bash
npm run build
sudo nginx -t && sudo systemctl reload nginx
```

### 4. Test

```bash
curl -s -o /dev/null -w "%{http_code}" -I "https://your-domain.com/1/api/1/envelope/"
```
Should return 405 (Method Not Allowed — HEAD on POST-only endpoint) or 400 (valid request reached GlitchTip), not 404.

## Verification

- Browser console: no `Invalid Sentry Dsn` error
- Sentry SDK initializes: `window.__SENTRY__` is defined
- Test events reach GlitchTip: check GlitchTip dashboard for new issues
