diff --git a/packages/wobe-documentation/doc/concepts/route.md b/packages/wobe-documentation/doc/concepts/route.md index 6e281d5..86bf862 100644 --- a/packages/wobe-documentation/doc/concepts/route.md +++ b/packages/wobe-documentation/doc/concepts/route.md @@ -65,3 +65,19 @@ const app = new Wobe() ) .listen(3000) ``` + +## Prelight requests + +You can enable prelight requests for cors like this : + +```ts +const app = new Wobe().options( + '*', + (ctx) => ctx.res.send(null), + cors({ + origin: 'http://localhost:3000', + allowHeaders: ['content-type'], + credentials: true, + }), +) +``` diff --git a/packages/wobe-documentation/doc/ecosystem/hooks/cors.md b/packages/wobe-documentation/doc/ecosystem/hooks/cors.md index a5230d7..4eaf298 100644 --- a/packages/wobe-documentation/doc/ecosystem/hooks/cors.md +++ b/packages/wobe-documentation/doc/ecosystem/hooks/cors.md @@ -4,7 +4,23 @@ Wobe has a `beforeHandker` hook to manage CORS. ## Example -You can only authorize some requests with the `origin` option. +You can only authorize some requests with the `origin` option + +First of all you will need to enable prelight requests for cors like this : + +```ts +const app = new Wobe().options( + '*', + (ctx) => ctx.res.send(null), + cors({ + origin: 'http://localhost:3000', + allowHeaders: ['content-type'], + credentials: true, + }), +) +``` + +than: ```ts import { Wobe, cors } from 'wobe'