payload icon indicating copy to clipboard operation
payload copied to clipboard

Endpoint PUT request gives 405 Method not allowed

Open ahmetskilinc opened this issue 2 years ago • 4 comments

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 avatar Oct 21 '24 13:10 ahmetskilinc

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.

gerardvanengelen avatar Oct 23 '24 05:10 gerardvanengelen

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

vitld avatar Oct 23 '24 18:10 vitld

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

github-actions[bot] avatar Nov 06 '24 15:11 github-actions[bot]

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

github-actions[bot] avatar Nov 08 '24 04:11 github-actions[bot]