-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: custom endpoints with
method: 'put'
(#9037)
### What? Fixes support for custom endpoints with `method: 'put'`. Previously, this didn't work: ```ts export default buildConfigWithDefaults({ collections: [ ], endpoints: [ { method: 'put', handler: () => new Response(), path: '/put', }, ], }) ``` ### Why? We supported this in 2.0 and docs are saying that we can use `'put'` as `method` https://payloadcms.com/docs/beta/rest-api/overview#custom-endpoints ### How? Implements the `REST_PUT` export for `@payloadcms/next/routes`, updates all templates. Additionally, adds tests to ensure root/collection level custom endpoints with all necessary methods execute properly. Fixes #8807 -->
- Loading branch information
Showing
13 changed files
with
218 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
templates/_template/src/app/(payload)/api/[...slug]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */ | ||
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */ | ||
import config from '@payload-config' | ||
import { REST_DELETE, REST_GET, REST_OPTIONS, REST_PATCH, REST_POST } from '@payloadcms/next/routes' | ||
import { | ||
REST_DELETE, | ||
REST_GET, | ||
REST_OPTIONS, | ||
REST_PATCH, | ||
REST_POST, | ||
REST_PUT, | ||
} from '@payloadcms/next/routes' | ||
|
||
export const GET = REST_GET(config) | ||
export const POST = REST_POST(config) | ||
export const DELETE = REST_DELETE(config) | ||
export const PATCH = REST_PATCH(config) | ||
export const PUT = REST_PUT(config) | ||
export const OPTIONS = REST_OPTIONS(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */ | ||
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */ | ||
import config from '@payload-config' | ||
import { REST_DELETE, REST_GET, REST_OPTIONS, REST_PATCH, REST_POST } from '@payloadcms/next/routes' | ||
import { | ||
REST_DELETE, | ||
REST_GET, | ||
REST_OPTIONS, | ||
REST_PATCH, | ||
REST_POST, | ||
REST_PUT, | ||
} from '@payloadcms/next/routes' | ||
|
||
export const GET = REST_GET(config) | ||
export const POST = REST_POST(config) | ||
export const DELETE = REST_DELETE(config) | ||
export const PATCH = REST_PATCH(config) | ||
export const PUT = REST_PUT(config) | ||
export const OPTIONS = REST_OPTIONS(config) |
10 changes: 9 additions & 1 deletion
10
templates/vercel-postgres/src/app/(payload)/api/[...slug]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */ | ||
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */ | ||
import config from '@payload-config' | ||
import { REST_DELETE, REST_GET, REST_OPTIONS, REST_PATCH, REST_POST } from '@payloadcms/next/routes' | ||
import { | ||
REST_DELETE, | ||
REST_GET, | ||
REST_OPTIONS, | ||
REST_PATCH, | ||
REST_POST, | ||
REST_PUT, | ||
} from '@payloadcms/next/routes' | ||
|
||
export const GET = REST_GET(config) | ||
export const POST = REST_POST(config) | ||
export const DELETE = REST_DELETE(config) | ||
export const PATCH = REST_PATCH(config) | ||
export const PUT = REST_PUT(config) | ||
export const OPTIONS = REST_OPTIONS(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */ | ||
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */ | ||
import config from '@payload-config' | ||
import { REST_DELETE, REST_GET, REST_OPTIONS, REST_PATCH, REST_POST } from '@payloadcms/next/routes' | ||
import { | ||
REST_DELETE, | ||
REST_GET, | ||
REST_OPTIONS, | ||
REST_PATCH, | ||
REST_POST, | ||
REST_PUT, | ||
} from '@payloadcms/next/routes' | ||
|
||
export const GET = REST_GET(config) | ||
export const POST = REST_POST(config) | ||
export const DELETE = REST_DELETE(config) | ||
export const PATCH = REST_PATCH(config) | ||
|
||
export const PUT = REST_PUT(config) | ||
export const OPTIONS = REST_OPTIONS(config) |
10 changes: 9 additions & 1 deletion
10
templates/with-payload-cloud/src/app/(payload)/api/[...slug]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */ | ||
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */ | ||
import config from '@payload-config' | ||
import { REST_DELETE, REST_GET, REST_OPTIONS, REST_PATCH, REST_POST } from '@payloadcms/next/routes' | ||
import { | ||
REST_DELETE, | ||
REST_GET, | ||
REST_OPTIONS, | ||
REST_PATCH, | ||
REST_POST, | ||
REST_PUT, | ||
} from '@payloadcms/next/routes' | ||
|
||
export const GET = REST_GET(config) | ||
export const POST = REST_POST(config) | ||
export const DELETE = REST_DELETE(config) | ||
export const PATCH = REST_PATCH(config) | ||
export const PUT = REST_PUT(config) | ||
export const OPTIONS = REST_OPTIONS(config) |
10 changes: 9 additions & 1 deletion
10
templates/with-postgres/src/app/(payload)/api/[...slug]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */ | ||
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */ | ||
import config from '@payload-config' | ||
import { REST_DELETE, REST_GET, REST_OPTIONS, REST_PATCH, REST_POST } from '@payloadcms/next/routes' | ||
import { | ||
REST_DELETE, | ||
REST_GET, | ||
REST_OPTIONS, | ||
REST_PATCH, | ||
REST_POST, | ||
REST_PUT, | ||
} from '@payloadcms/next/routes' | ||
|
||
export const GET = REST_GET(config) | ||
export const POST = REST_POST(config) | ||
export const DELETE = REST_DELETE(config) | ||
export const PATCH = REST_PATCH(config) | ||
export const PUT = REST_PUT(config) | ||
export const OPTIONS = REST_OPTIONS(config) |
10 changes: 9 additions & 1 deletion
10
templates/with-vercel-mongodb/src/app/(payload)/api/[...slug]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */ | ||
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */ | ||
import config from '@payload-config' | ||
import { REST_DELETE, REST_GET, REST_OPTIONS, REST_PATCH, REST_POST } from '@payloadcms/next/routes' | ||
import { | ||
REST_DELETE, | ||
REST_GET, | ||
REST_OPTIONS, | ||
REST_PATCH, | ||
REST_POST, | ||
REST_PUT, | ||
} from '@payloadcms/next/routes' | ||
|
||
export const GET = REST_GET(config) | ||
export const POST = REST_POST(config) | ||
export const DELETE = REST_DELETE(config) | ||
export const PATCH = REST_PATCH(config) | ||
export const PUT = REST_PUT(config) | ||
export const OPTIONS = REST_OPTIONS(config) |
10 changes: 9 additions & 1 deletion
10
templates/with-vercel-postgres/src/app/(payload)/api/[...slug]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */ | ||
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */ | ||
import config from '@payload-config' | ||
import { REST_DELETE, REST_GET, REST_OPTIONS, REST_PATCH, REST_POST } from '@payloadcms/next/routes' | ||
import { | ||
REST_DELETE, | ||
REST_GET, | ||
REST_OPTIONS, | ||
REST_PATCH, | ||
REST_POST, | ||
REST_PUT, | ||
} from '@payloadcms/next/routes' | ||
|
||
export const GET = REST_GET(config) | ||
export const POST = REST_POST(config) | ||
export const DELETE = REST_DELETE(config) | ||
export const PATCH = REST_PATCH(config) | ||
export const PUT = REST_PUT(config) | ||
export const OPTIONS = REST_OPTIONS(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters