Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature-request: Use storyblok functions from this package directly on API routes #440

Open
1 task done
chstappert opened this issue Jun 8, 2023 · 3 comments
Open
1 task done
Assignees
Labels
dx [Issue] Improvement or fix with impact on the developer experience. enhancement [Issue][PR] New feature improvement [Issue][PR] Refactor or code improvement

Comments

@chstappert
Copy link

chstappert commented Jun 8, 2023

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

/* Use storyblok/nuxt package on a nuxt API route like this:  */

import { useStoryblokApi } from '@storyblok/nuxt' // and async functions

export default defineEventHandler(async (event) => {

const story = await useStoryblokApi().getStory('someStory') {...})

return story.data.story 

})

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

@chstappert chstappert added enhancement [Issue][PR] New feature pending-author [Issue] Awaiting further information or action from the issue author pending-triage [Issue] Ticket is pending to be prioritised labels Jun 8, 2023
@chstappert chstappert changed the title feature-request: Use storyblok functions from storyblok/nuxt package directly on API routes feature-request: Use storyblok functions from this package directly on API routes Jun 8, 2023
@alvarosabu alvarosabu self-assigned this Jun 16, 2023
@alvarosabu
Copy link
Contributor

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 server utility for Nitro.

@Dawntraoz Dawntraoz added improvement [Issue][PR] Refactor or code improvement dx [Issue] Improvement or fix with impact on the developer experience. and removed pending-author [Issue] Awaiting further information or action from the issue author pending-triage [Issue] Ticket is pending to be prioritised labels Jun 19, 2023
@steffkes
Copy link

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

@zacwebb
Copy link

zacwebb commented Aug 21, 2023

I'm currently having to setup a separate instance of storyblok-js-client to make calls to the content delivery API from my server/api routes 😕 would be really nice to just use the Nuxt library exclusively

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dx [Issue] Improvement or fix with impact on the developer experience. enhancement [Issue][PR] New feature improvement [Issue][PR] Refactor or code improvement
Projects
None yet
Development

No branches or pull requests

5 participants