Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint PUT request gives 405 Method not allowed #8807

Closed
ahmetskilinc opened this issue Oct 21, 2024 · 4 comments · Fixed by #9037
Closed

Endpoint PUT request gives 405 Method not allowed #8807

ahmetskilinc opened this issue Oct 21, 2024 · 4 comments · Fixed by #9037

Comments

@ahmetskilinc
Copy link
Contributor

Describe the Bug

I've added a PUT method to my application inside the payload config and when I hit this endpoint I get a 405 error. GET request works perfectly fine.

Link to the code that reproduces this issue

https://github.com/ahmetskilinc/endpoints-not-working-payload

Reproduction Steps

  1. clone repo
  2. pnpm install
  3. pnpm dev
  4. open postman (or any API testing program)
  5. make a PUT request to localhost:3000/api/square-signup

Which area(s) are affected? (Select all that apply)

area: core

Environment Info

Payload: 3.0.0-beta.116
NextJS: 15.0.0-canary.198
NodeJS: 20.12.0
React: 19.0.0-rc-b8ae38f8-20241018

@ahmetskilinc ahmetskilinc added status: needs-triage Possible bug which hasn't been reproduced yet v3 labels Oct 21, 2024
@gerardvanengelen
Copy link

This is because Payload overwrites the next api funtionallity.
I've work around this by putting my own api's in a folder apiv2 and using apiv2/{endpoint_name}

Not the prettiest, but it works.

@ViktorPontinen
Copy link

ViktorPontinen commented Oct 23, 2024

Just stumbled across the same issue.
Creating custom endpoint in collection like so:

  endpoints: [
    {
      path: '/custom-endpoint',
      method: 'put',
      handler: async (req) => {
        return Response.json({ success: true })
      }
    }
  ]

Gives 405 Method not allowed when making fetch call from client.

EDIT: Version v3.0.0-beta.117

@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Nov 5, 2024
r1tsuu added a commit that referenced this issue Nov 5, 2024
### 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

-->
Copy link
Contributor

github-actions bot commented Nov 6, 2024

🚀 This is included in version v3.0.0-beta.125

Copy link
Contributor

github-actions bot commented Nov 8, 2024

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants