You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rest-api/overview.mdx
+25Lines changed: 25 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -703,6 +703,31 @@ import { addLocalesToRequestFromData } from 'payload'
703
703
}
704
704
```
705
705
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
+
returnResponse.json(
719
+
{ message: 'success' },
720
+
{
721
+
headers: headersWithCors({
722
+
headers: newHeaders(),
723
+
req,
724
+
})
725
+
},
726
+
)
727
+
}
728
+
}
729
+
```
730
+
706
731
## Method Override for GET Requests
707
732
708
733
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