payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
24.86k stars 1.58k forks source link

Endpoint PUT request gives 405 Method not allowed #8807

Open ahmetskilinc opened 1 week ago

ahmetskilinc commented 1 week ago

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

gerardvanengelen commented 1 week ago

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 commented 1 week ago

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