image
image copied to clipboard
add support for image helpers in nitro endpoints
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.