Skip to content

Commit 77395b6

Browse files
authored
docs: adds info and example for headersWithCors (#11141)
1 parent fcaf591 commit 77395b6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/rest-api/overview.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,31 @@ import { addLocalesToRequestFromData } from 'payload'
703703
}
704704
```
705705

706+
`headersWithCors`
707+
708+
By default, custom endpoints don't handle CORS headers in responses. The `headersWithCors` function checks the Payload config and sets the appropriate CORS headers in the response accordingly.
709+
710+
```ts
711+
import { headersWithCors } from 'payload'
712+
713+
// custom endpoint example
714+
{
715+
path: '/:id/tracking',
716+
method: 'post',
717+
handler: async (req) => {
718+
return Response.json(
719+
{ message: 'success' },
720+
{
721+
headers: headersWithCors({
722+
headers: new Headers(),
723+
req,
724+
})
725+
},
726+
)
727+
}
728+
}
729+
```
730+
706731
## Method Override for GET Requests
707732

708733
Payload supports a method override feature that allows you to send GET requests using the HTTP POST method. This can be particularly useful in scenarios when the query string in a regular GET request is too long.

0 commit comments

Comments
 (0)