# Game Server - Modal FastAPI Proxy

A FastAPI webserver running on Modal that serves minigames using subpath routing. Each game lives at a custom subpath like `vibe-sites.suno.fm/<game-id>/*`.

## Features

- **Subpath Routing**: Each game accessible via `vibe-sites.suno.fm/<game-id>/*`
- **Proxy Functionality**: Proxies requests to corresponding `.suno.run` domains
- **Iframe-Friendly**: Modifies security headers to allow content to be embedded in iframes
- **Async Performance**: Built with FastAPI and httpx for high-performance async operations

## Architecture

```
vibe-sites.suno.fm/ttunes/* → Proxy → ttunes.suno.run/*
vibe-sites.suno.fm/<game-id>/* → Proxy → <game-id>.suno.run/*
```

## Setup

### 1. Install Dependencies

```bash
cd game-server
pip install -r requirements.txt
```

### 2. Deploy to Modal

```bash
modal deploy main.py
```

### 3. Configure DNS

The domain `vibe-sites.suno.fm` is configured in the code via the `custom_domains` parameter. After deploying, you'll need to:

1. Configure DNS for `vibe-sites.suno.fm` to point to Modal's servers
2. Follow Modal's DNS configuration instructions (typically shown after deployment)
3. Add the necessary CNAME or A records as specified by Modal

## Usage

Once deployed, you can access games at:

- `https://vibe-sites.suno.fm/ttunes/` - Proxies ttunes.suno.run
- `https://vibe-sites.suno.fm/<game-id>/` - Proxies <game-id>.suno.run

## Development

Run locally with Modal:

```bash
modal serve main.py
```

This will start a local development server.

## How It Works

1. **Request Reception**: FastAPI receives a request at `vibe-sites.suno.fm/<game-id>/*`
2. **Path Parsing**: Extracts the first path segment (`<game-id>`)
3. **Target Mapping**: Maps to `<game-id>.suno.run`
4. **Path Forwarding**: Forwards the remaining path to the target
5. **Proxying**: Forwards the request using httpx
6. **Header Modification**: Removes/modifies headers to make content iframeable:
   - Removes `X-Frame-Options` restrictions
   - Removes restrictive `Content-Security-Policy`
   - Adds `Access-Control-Allow-Origin: *`
7. **Response**: Returns the modified response

## Security Headers Modified

To make content iframeable, we modify these headers:

- `X-Frame-Options`: Changed to `ALLOWALL`
- `Content-Security-Policy`: Removed if restrictive
- `Access-Control-Allow-Origin`: Set to `*`

## Adding New Games

To add a new game, simply ensure the target domain exists at `<game-id>.suno.run`. The proxy will automatically handle routing from `vibe-sites.suno.fm/<game-id>/*` to `<game-id>.suno.run/*`.

## Troubleshooting

- **502 Bad Gateway**: The target domain may be down or unreachable
- **404 Not Found**: Ensure you're using the format `vibe-sites.suno.fm/<game-id>/*`
- **CORS issues**: Check that the proxy is properly modifying headers

## Examples

- `https://vibe-sites.suno.fm/ttunes/` → `https://ttunes.suno.run/`
- `https://vibe-sites.suno.fm/ttunes/index.html` → `https://ttunes.suno.run/index.html`
- `https://vibe-sites.suno.fm/game123/api/data` → `https://game123.suno.run/api/data`
# interact-hack
