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

add support for image helpers in nitro endpoints #1447

Open
JasonXDDD opened this issue Aug 28, 2024 · 2 comments · May be fixed by #1473
Open

add support for image helpers in nitro endpoints #1447

JasonXDDD opened this issue Aug 28, 2024 · 2 comments · May be fixed by #1473
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@JasonXDDD
Copy link

I want to generate image url path on my server api response. it's my composable useImageUrl.js

export default (src) => {
  const img = useImage()

  const imgUrl = img(`/${src}.png`, {
    format: 'webp',
    quality: 80,
  })

  return imgUrl
}

and my server api:

import useImageUrl from '~/composables/utils/useImageUrl'


export default defineEventHandler(async (event) => {
  const { code } = event.context.params
  return {
     path: useImageUrl(code)
  }
})

but when I yarn dev, it shows the error:

[nuxt] [request error] [unhandled] [500] useImage is not defined
  at useImageUrl (./composables/utils/useImageUrl.js:2:15)
  at Object.handler (./server/api/deck/[code].get.js:65:1)
  at async ./node_modules/h3/dist/index.mjs:1975:19
  at async Object.callAsync (./node_modules/unctx/dist/index.mjs:72:16)
  at async toNodeHandle (./node_modules/h3/dist/index.mjs:2266:7)
  at async ufetch (./node_modules/unenv/runtime/fetch/index.mjs:9:17)
  at async $fetchRaw2 (./node_modules/ofetch/dist/shared/ofetch.37386b05.mjs:222:26)
  at async $fetchRaw2 (./node_modules/ofetch/dist/shared/ofetch.37386b05.mjs:263:14)
  at async $fetch2 (./node_modules/ofetch/dist/shared/ofetch.37386b05.mjs:268:15)
  at async ./pages/deck/[code].vue:69:18

Is it support on server side? or any other way let me generate image url?

thanks.

@JasonXDDD JasonXDDD changed the title Can I use useImage() composible on the server side api ? Can I use useImage() composable on the server side api ? Aug 28, 2024
@danielroe danielroe added enhancement New feature or request good first issue Good for newcomers labels Aug 28, 2024
@danielroe danielroe changed the title Can I use useImage() composable on the server side api ? add support for image helpers in nitro endpoints Aug 28, 2024
@Afshar07
Copy link

Hey, @danielroe, Can i work on this?
I'm eager for my first contribution to be in nuxt community!

@danielroe
Copy link
Member

That would be great! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants