# Pub.dev CORS Proxy

A lightweight proxy server designed to facilitate `dart pub get` operations from browser environments (e.g., Web Workers) by adding necessary CORS headers and rewriting archive URLs.

This service proxies specific `pub.dev` endpoints required for dependency resolution and package retrieval, allowing `pub` (compiled to JavaScript via `dart2js`) to function within a web context.

## 🚀 Features

-   **CORS Support**: Adds `Access-Control-Allow-Origin` headers to allow cross-origin requests.
-   **URL Rewriting**: Automatically rewrites package archive URLs in the package manifest to point to this proxy.
-   **Streaming**: Efficiently streams package archives without buffering.
-   **Minimal Footprint**: Built with `shelf` and compiled to a native executable via Docker.

## 🛠️ API Endpoints

The server exposes the following endpoints (following the [Hosted Pub Repository Spec v2](doc/repository-spec-v2.md)):

-   `GET /`: Returns this README.
-   `GET /api/packages/<package>`: Proxies package versions and metadata, rewriting archive URLs.
-   `GET /api/packages/<package>/advisories`: Proxies security advisories.
-   `GET /files/<package>/<version>.tar.gz`: Proxies the package archive download.

## ⚙️ Configuration

The server can be configured using the following environment variables:

| Variable | Description | Default |
| :--- | :--- | :--- |
| `PORT` | The HTTP port to listen on. | `8080` |
| `ALLOWED_ORIGINS` | A comma-separated list of allowed origins for CORS. Set to `*` to allow all. | `*` (All origins) |

### Example

```bash
# Allow specific origins
ALLOWED_ORIGINS=https://myapp.com,https://staging.myapp.com PORT=3000 ./bin/server
```

## 🐳 Deployment

A `Dockerfile` is provided for easy deployment to platforms like Coolify, Cloud Run, or any Docker-compatible host.

```bash
docker build -t pub-cors-proxy .
docker run -p 8080:8080 pub-cors-proxy
```