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?
Or is there some field/function I can use to find out which endpoints are currently "registered" in express?
@Alessio 🍣 app._router.stack, or router.stack should list all registered routes
depending on how your express setup looks
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.
Thank you, that worked! For anyone needing this, I used this function to display all routes & endpoints in a pretty way:
app._router.stack.forEach((r) => {
if (r.route && r.route.path) {
console.log(r.route.path);
} else if (r.name === "router" && r.handle.stack) {
r.handle.stack.forEach((r2) => {
if (r2.route && r2.route.path) {
console.log(r2.route.path);
}
});
}
});
thank you, I did actually! Just figured out why it didn't work. And damn it's stupid...
I had a different plugin which did this
So it overrode all my endpoints as I forgot to use the spread syntax there 😅
Ah good catch, glad it is working!
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.