#Adding endpoints as a plugin does not work?

10 messages · Page 1 of 1 (latest)

near bough
#

https://github.com/AlessioGr/payload-plugin-lexical/blob/master/src/index.ts#L17

Is it not possible to add an endpoint to payload like that, in a plugin? Running the plugin demo, it works perfectly. But when actually installing the plugin, the new endpoint I added for some reason is not available, even though the code gets executed. ("Cannot GET /api/openai-completion")

Should it not be possible for plugins to add endpoints like that? Is it better to do that using express directly?

near bough
#

Or is there some field/function I can use to find out which endpoints are currently "registered" in express?

uncut parrot
#

@near bough app._router.stack, or router.stack should list all registered routes

#

depending on how your express setup looks

boreal dirge
#

It should work. Are you sure you set pluginOptions?.ai?.openai_key? (your env file is in your repo and it's not in there and also not set in your script.)

#

I did same thing in my payload.swagger plugin and it works just fine. I did spread the endpoints, to keep the function pure, but that doesn't explain why it doesn't work for you.

near bough
near bough
#

I had a different plugin which did this

#

So it overrode all my endpoints as I forgot to use the spread syntax there 😅