feature-request: Use storyblok functions from this package directly on API routes #243
Replies: 6 comments
-
|
Hi @chstappert thanks for reaching out. So Vue composables are meant to work under a setup context, which means, inside components. Since server routes in Nuxt work with Nitro, I'm afraid composables won't work here. An option would be to create a |
Beta Was this translation helpful? Give feedback.
-
|
I'd second that! If you're trying to satisfy the requirement from nuxt's simple-sitemap to provide a list of dynamic urls - obviously based on what we have in storyblok, this little addition would be superb. Otherwise we're doing the whole initialization again, potentially duplicating our config |
Beta Was this translation helpful? Give feedback.
-
|
I'm currently having to setup a separate instance of |
Beta Was this translation helpful? Give feedback.
-
|
Hey, The issue has been open for ~1.5 years, but IMO this feature should have a way higher priority. When using the module, the access key is exposed in the frontend which is a very bad practice. Every major Nuxt 3 module that handles some sort of API facilitation has nitro utilities to handle this. Also, a server utility would give users more control about how they would like their data to be handled. Caching storyblok responses for example would be way easier if a nitro endpoint could just take care of it. |
Beta Was this translation helpful? Give feedback.
-
|
Hi all, thanks for the feedback, maybe I can provide some context on why this feature isn't prioritized.
I understand the concern but the
Rest assured, most of Storyblok websites operate like this. You don't need to worry about it. Source https://www.storyblok.com/docs/api/content-delivery/v2/getting-started/authentication
Wouldn't that be mixing paradigms? If you make calls on the server you would be replacing doing: to use your Nuxt API endpoint like this So you no longer need the Storyblok JS instance at all in the client. If you go the server API routes way you are basically resigning the DX provided by the module, you have more control tho. This doesn't mean we are not considering this feature to be included eventually, it just falls short vs other priorities in the ecosystem atm. |
Beta Was this translation helpful? Give feedback.
-
|
Hey all, we just opened a PR that solves the need here. Feel free to re-open if you encounter any issues |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
Can we import storyblok/nuxt directly on a nuxt API route instead of using the client? The setup is already done in the nuxt.config. Since the functions are only in the composable context, it would be nice to use them now on the API routes to get data and combine them with some logic.
Suggested solution or improvement
Additional context
I want to get data from storyblok, cache them with Nitro, and use the CMS data for our own (independent) endpoint to have consistent data and a clean setup.
Validations
Beta Was this translation helpful? Give feedback.
All reactions