Golem add cors rust

From golemcloud/golem · View interactive version

Golem add cors rust is an AI agent skill from the GitHub repository golemcloud/golem. 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.

How to use this skill

Skill file

Configuring CORS for Rust HTTP Endpoints

Mount-Level CORS

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

#[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:

#[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:

#[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.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.