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
* {@linkcode App} instance.
*
* @example
* @example Testing
* ```ts
* const builder = new Builder();
* 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.
* @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<State> = {
* 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<State>(options?: CORSOptions<State>): Middleware<State> {