# Custom Routes in Web Chat Server

This reference shows how to add custom pages and static file serving to the Hermes webchat server.

## Adding a Video Page (Example)

The following changes were made to `/root/.hermes/webchat/server.py` to add a `/video` page:

### 1. Add serve_file method to Handler class

```python
def serve_file(self, filepath, content_type):
    """Serve a static file"""
    try:
        with open(filepath, 'rb') as f:
            data = f.read()
        self.send_response(200)
        self.send_header('Content-Type', content_type)
        self.send_header('Content-Length', str(len(data)))
        self.send_header('Accept-Ranges', 'bytes')
        self.end_headers()
        self.wfile.write(data)
    except FileNotFoundError:
        self.send_response(404)
        self.end_headers()
```

### 2. Add VIDEO_PAGE HTML constant

Place between LOGIN_PAGE and CHAT_PAGE definitions.

### 3. Add routes in do_GET

Add route checks AFTER auth check, BEFORE the CHAT_PAGE fallback:

```python
# Custom page route
if self.path == '/video' or self.path == '/video/':
    self.send_response(200)
    self.send_header('Content-Type', 'text/html; charset=utf-8')
    self.end_headers()
    self.wfile.write(VIDEO_PAGE.encode())
    return

# Static file route
if self.path == '/static/somefile.mp4':
    self.serve_file('/path/to/somefile.mp4', 'video/mp4')
    return
```

### 4. Place static files

```bash
mkdir -p /root/.hermes/webchat/static
cp /path/to/file.mp4 /root/.hermes/webchat/static/
```

### 5. Restart service

```bash
systemctl restart hermes-webchat
```

Note: This triggers an approval gate. Ask the user to confirm or run it manually.

## General Pattern for Custom Routes

1. Define HTML constant (e.g., `MY_PAGE`)
2. Add route check in `do_GET()` after auth check, before CHAT_PAGE fallback
3. For static files, use `serve_file()` method
4. Place static assets under `/root/.hermes/webchat/static/` or any known path
5. Restart webchat service
