payload icon indicating copy to clipboard operation
payload copied to clipboard

`plugin-seo` does not respect basePath config in NextJS for generation (potentially all `endpoint` paths)

Open neverether opened this issue 6 months ago • 0 comments

Link to reproduction

No response

Payload Version

3.0.0-beta.90

Node Version

20

Next.js Version

15.0.0-canary.120

Describe the Bug

While using plugin-seo's generate* functions, the endpoint path is set to /api/plugin-seo/generate-*

When using a basePath configuration this will 404 or in my case, hit the wrong application.

Reproduction Steps

  1. App Setup as a multi-zone app (in my case a monorepo):
  • Main Client App (localhost:3000)
  • Payload App w/basePath /blog (localhost:3001/blog)
  1. Enable plugin-seo and configure generateTItle
  2. When clicking Generate Title:
blog:dev:  POST /api/payload-preferences/collection-blog-posts-66c742481f4097f096b85aba 200 in 113ms
client:dev:  POST /api/plugin-seo/generate-title 404 in 28ms

The endpoint is requesting localhost:3000/api/... and hits the wrong client 4. As a workaround, adding a rewrite to the client app to add the basePath manually, but this may not be an option depending on the users' situations:

{
  source: "/api/plugin-seo/:path*",
  destination: `${blogHost}/api/plugin-seo/:path*`,
},

will then correctly hit the endpoint

blog:dev:  POST /api/payload-preferences/collection-blog-posts-66c742481f4097f096b85aba 200 in 33ms
blog:dev:  POST /api/plugin-seo/generate-title 200 in 20ms

Note: I looked at the code https://github.com/payloadcms/payload/blob/9de3ffdcfe8cda147616e29e0c86d067e9650dec/packages/plugin-seo/src/index.tsx#L132-L148 and based on the configuration, there may be a larger issue here where endpoint configs all don't respect basePath. I don't have any experience with the endpoint feature yet so I can't confirm this is the case.

Adapters and Plugins

plugin-seo

neverether avatar Aug 23 '24 01:08 neverether