# Golem Add Cors Rust

> Configuring CORS for Rust HTTP endpoints. Use when the user asks to enable CORS, allow cross-origin requests, or configure allowed origins for HTTP endpoints.

- Skill: `golemcloud/golem-add-cors-rust` (Agent Skill)
- Install (CLI): `npx skillmds@latest add golemcloud/golem-add-cors-rust`
- Raw SKILL.md: https://api.skillmd.com/api/skills/golemcloud/golem-add-cors-rust/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: golemcloud (https://skillmd.com/u/golemcloud)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/golemcloud/golem-add-cors-rust

---


# Configuring CORS for Rust HTTP Endpoints

## Mount-Level CORS

Set `cors` on `#[agent_definition]` to apply allowed origins to **all** endpoints:

```rust
#[agent_definition(
    mount = "/api/{name}",
    cors = ["https://app.example.com"]
)]
pub trait MyAgent {
    fn new(name: String) -> Self;

    #[endpoint(get = "/data")]
    fn get_data(&self) -> Data;
    // Allows https://app.example.com
}
```

## Endpoint-Level CORS

Set `cors` on `#[endpoint]` to add allowed origins for a specific endpoint. Origins are **unioned** with mount-level CORS:

```rust
#[agent_definition(
    mount = "/api/{name}",
    cors = ["https://app.example.com"]
)]
pub trait MyAgent {
    fn new(name: String) -> Self;

    #[endpoint(get = "/data", cors = ["*"])]
    fn get_data(&self) -> Data;
    // Allows BOTH https://app.example.com AND * (all origins)

    #[endpoint(get = "/other")]
    fn get_other(&self) -> Data;
    // Inherits mount-level: only https://app.example.com
}
```

## Wildcard

Use `"*"` to allow all origins:

```rust
#[agent_definition(mount = "/public/{name}", cors = ["*"])]
pub trait PublicAgent {
    fn new(name: String) -> Self;
}
```

## CORS Preflight

Golem automatically handles `OPTIONS` preflight requests for endpoints that have CORS configured. The preflight response includes `Access-Control-Allow-Origin`, `Access-Control-Allow-Methods`, and `Access-Control-Allow-Headers` headers.

