Files
payload/test/config/config.ts
Hulpoi George-Valentin 9c72ab97b0 feat: configure cors allowed headers (#6837)
## Description

Currently, the Payload doesn't support to extend the Allowed Headers in
CORS context. With this PR, `cors` property can be an object with
`origins` and `headers`.

- [x] I have read and understand the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository.

## Type of change

- [ ] Chore (non-breaking change which does not add functionality)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Change to the
[templates](https://github.com/payloadcms/payload/tree/main/templates)
directory (does not affect core functionality)
- [ ] Change to the
[examples](https://github.com/payloadcms/payload/tree/main/examples)
directory (does not affect core functionality)
- [x] This change requires a documentation update

## Checklist:

- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] Existing test suite passes locally with my changes
- [x] I have made corresponding changes to the documentation

Co-authored-by: Alessio Gravili <alessio@gravili.de>
2024-07-15 13:26:29 -04:00

121 lines
2.8 KiB
TypeScript

import { fileURLToPath } from 'node:url'
import path from 'path'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
import { devUser } from '../credentials.js'
export default buildConfigWithDefaults({
collections: [
{
slug: 'pages',
access: {
create: () => true,
delete: () => true,
read: () => true,
update: () => true,
},
custom: {
externalLink: 'https://foo.bar',
},
endpoints: [
{
custom: { examples: [{ type: 'response', value: { message: 'hi' } }] },
handler: () => {
return Response.json({ message: 'hi' })
},
method: 'get',
path: '/hello',
},
],
fields: [
{
name: 'title',
type: 'text',
custom: {
description: 'The title of this page',
},
},
{
name: 'myBlocks',
type: 'blocks',
blocks: [
{
slug: 'blockOne',
custom: {
description: 'The blockOne of this page',
},
fields: [
{
name: 'blockOneField',
type: 'text',
},
{
name: 'blockTwoField',
type: 'text',
},
],
},
],
custom: {
description: 'The blocks of this page',
},
},
],
},
],
custom: { name: 'Customer portal' },
endpoints: [
{
custom: { description: 'Get the sanitized payload config' },
handler: (req) => {
return Response.json(req.payload.config)
},
method: 'get',
path: '/config',
},
],
globals: [
{
slug: 'my-global',
custom: { foo: 'bar' },
endpoints: [
{
custom: { params: [{ name: 'name', type: 'string', in: 'query' }] },
handler: (req) => {
const sp = new URL(req.url).searchParams
return Response.json({ message: `Hi ${sp.get('name')}!` })
},
method: 'get',
path: '/greet',
},
],
fields: [
{
name: 'title',
type: 'text',
custom: {
description: 'The title of my global',
},
},
],
},
],
onInit: async (payload) => {
await payload.create({
collection: 'users',
data: {
email: devUser.email,
password: devUser.password,
},
})
},
typescript: {
outputFile: path.resolve(dirname, 'payload-types.ts'),
},
cors: {
origins: '*',
headers: ['x-custom-header'],
},
})