From 23734a00b24a2a69775e31a5c326f04c93462eb7 Mon Sep 17 00:00:00 2001 From: Christian Svensson Date: Tue, 11 Nov 2025 15:33:54 +0100 Subject: [PATCH] docs(core): improve CORS example documentation on JSR (#3602) Improves clarity of CORS JSDoc example for JSR: image ## Changes - Split the example into two: Basic & Advances - Uncomment "Advanced" example --- packages/fresh/src/dev/builder.ts | 2 +- packages/fresh/src/middlewares/cors.ts | 28 ++++++++++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/fresh/src/dev/builder.ts b/packages/fresh/src/dev/builder.ts index 95b9fac2..32fd3557 100644 --- a/packages/fresh/src/dev/builder.ts +++ b/packages/fresh/src/dev/builder.ts @@ -213,7 +213,7 @@ export class Builder { * This can also be used for testing to apply a snapshot to a particular * {@linkcode App} instance. * - * @example + * @example Testing * ```ts * const builder = new Builder(); * const applySnapshot = await builder.build({ snapshot: "memory" }); diff --git a/packages/fresh/src/middlewares/cors.ts b/packages/fresh/src/middlewares/cors.ts index 00fd0904..58010046 100644 --- a/packages/fresh/src/middlewares/cors.ts +++ b/packages/fresh/src/middlewares/cors.ts @@ -37,7 +37,7 @@ export type CORSOptions = { * @param [options] - The options for the CORS middleware. * @returns The Fresh middleware handler function. * - * @example + * @example Basic usage * ```ts * // main.ts or routes/_middleware.ts * import { cors } from 'fresh'; @@ -46,19 +46,21 @@ export type CORSOptions = { * cors({ origin: '*' }), // Allow all origins * // other middlewares or main route handler * ]; + * ``` * - * // Example with options: - * // export const handler = [ - * // 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, - * // }), - * // // ... - * // ]; + * @example Advanced usage + * ```ts + * export const handler = [ + * 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, + * }), + * // ... + * ]; * ``` */ export function cors(options?: CORSOptions): Middleware {