docs(core): improve CORS example documentation on JSR (#3602)

Improves clarity of CORS JSDoc example for JSR:

<img width="1088" height="706" alt="image"
src="https://github.com/user-attachments/assets/8ea3b6f9-a5ee-41cc-9512-a3a0fb87a4c0"
/>

## Changes

- Split the example into two: Basic & Advances
- Uncomment "Advanced" example
This commit is contained in:
Christian Svensson
2025-11-11 15:33:54 +01:00
committed by GitHub
parent 6a1ce911d0
commit 23734a00b2
2 changed files with 16 additions and 14 deletions
+1 -1
View File
@@ -213,7 +213,7 @@ export class Builder<State = any> {
* This can also be used for testing to apply a snapshot to a particular * This can also be used for testing to apply a snapshot to a particular
* {@linkcode App} instance. * {@linkcode App} instance.
* *
* @example * @example Testing
* ```ts * ```ts
* const builder = new Builder(); * const builder = new Builder();
* const applySnapshot = await builder.build({ snapshot: "memory" }); * const applySnapshot = await builder.build({ snapshot: "memory" });
+15 -13
View File
@@ -37,7 +37,7 @@ export type CORSOptions<State> = {
* @param [options] - The options for the CORS middleware. * @param [options] - The options for the CORS middleware.
* @returns The Fresh middleware handler function. * @returns The Fresh middleware handler function.
* *
* @example * @example Basic usage
* ```ts * ```ts
* // main.ts or routes/_middleware.ts * // main.ts or routes/_middleware.ts
* import { cors } from 'fresh'; * import { cors } from 'fresh';
@@ -46,19 +46,21 @@ export type CORSOptions<State> = {
* cors({ origin: '*' }), // Allow all origins * cors({ origin: '*' }), // Allow all origins
* // other middlewares or main route handler * // other middlewares or main route handler
* ]; * ];
* ```
* *
* // Example with options: * @example Advanced usage
* // export const handler = [ * ```ts
* // cors({ * export const handler = [
* // origin: 'http://example.com', * cors({
* // allowHeaders: ['X-Custom-Header', 'Upgrade-Insecure-Requests'], * origin: 'http://example.com',
* // allowMethods: ['POST', 'GET', 'OPTIONS'], * allowHeaders: ['X-Custom-Header', 'Upgrade-Insecure-Requests'],
* // exposeHeaders: ['Content-Length', 'X-Kuma-Revision'], * allowMethods: ['POST', 'GET', 'OPTIONS'],
* // maxAge: 600, * exposeHeaders: ['Content-Length', 'X-Kuma-Revision'],
* // credentials: true, * maxAge: 600,
* // }), * credentials: true,
* // // ... * }),
* // ]; * // ...
* ];
* ``` * ```
*/ */
export function cors<State>(options?: CORSOptions<State>): Middleware<State> { export function cors<State>(options?: CORSOptions<State>): Middleware<State> {