Files
sweet/docs/canary/plugins/cors.md
T
Marvin Hagemeister a703e79181 docs: update canary docs for Fresh 2 (#3108)
There are still some rough edges here and there, but it's in a much
better shape than what we have today.
2025-07-18 15:18:38 +02:00

845 B

description
description
Set CORS HTTP headers with the cors middleware

The cors() middleware can be used to add Cross-Origin-Resource-Sharing headers to HTTP requests. These allow the server to indicate which origins (domains, scheme or port) other than its own is permitted to load resources from.

import { cors } from "fresh";

const app = new App()
  .use(cors({
    origin: "http://example.com",
    allowHeaders: ["X-Custom-Header", "Upgrade-Insecure-Requests"],
    allowMethods: ["POST", "GET", "OPTIONS"],
    exposeHeaders: ["Content-Length", "X-Kuma-Revision"],
    maxAge: 600,
    credentials: true,
  }))
  .get("/", () => new Response("hello"));

Options

See the API docs for a list of all supported options