docs: adds info and example for headersWithCors (#11141)

This commit is contained in:
Said Akhrarov
2025-02-28 13:43:00 -05:00
committed by GitHub
parent fcaf59176d
commit 77395b6483

View File

@@ -703,6 +703,31 @@ import { addLocalesToRequestFromData } from 'payload'
}
```
`headersWithCors`
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.
```ts
import { headersWithCors } from 'payload'
// custom endpoint example
{
path: '/:id/tracking',
method: 'post',
handler: async (req) => {
return Response.json(
{ message: 'success' },
{
headers: headersWithCors({
headers: new Headers(),
req,
})
},
)
}
}
```
## Method Override for GET Requests
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.