zynagent-first application framework

Back to the API reference

zyn.Cors#

/// Built-in cross-origin resource sharing middleware.
pub const Cors = struct {
    /// Origins permitted to read cross-origin responses.
    pub const Origins = union(enum) {
        any,
        allow: []const []const u8,
    };
    
    /// Compile-time cross-origin resource sharing policy.
    pub const Config = struct {
        origins: Origins,
        methods: []const []const u8 = &.{ "GET", "HEAD", "POST" },
        headers: []const []const u8 = &.{},
        exposed_headers: []const []const u8 = &.{},
        allow_credentials: bool = false,
        max_age_seconds: ?u32 = null,
    };
    
    /// Applies a configured CORS policy and answers valid preflight requests.
    pub fn handle(
        comptime config: Config,
        middleware: *zyn.Middleware,
    ) !void;
};