nuxt-modules / og-image

Generate OG Images with Vue templates in Nuxt.
https://nuxtseo.com/og-image
415 stars 27 forks source link

Query Parameters ignored #107

Closed jeannen closed 11 months ago

jeannen commented 1 year ago

Describe the bug

Hey!

It seems like the query parameters aren't properly passed in the API URL

A fix could be to append the query parameters at the end of the API endpoint

/api/og-image-options?path=/page-path&query1=value1&query2=value2

Reproduction

I have a page with the URL /tools/transcribe-to-text?format=mp3

The template is /tools/transcribe-to-text, and change the content based on the query parameter (for example, title will be "Transcribe your [•••] file to text")

I did not plan to have a "default" value in case there was no query parameter. When I tried to access the picture, I got an error saying the module couldn't resolve the path. But it also showed that the /api/og-image-options endpoint didn't took query parameters into consideration.

I added a default value to avoid the crash, but then it just shows the default value in the image.

If that helps, here is the error when I had no default value (meaning the page was returning internal error)

[nuxt] [request error] [unhandled] [500] [GET] "/api/og-image-options?path=/tools/transcribe-to-text": 500 Failed to read the path /tools/transcribe-to-text for og-image extraction. [GET] "/tools/transcribe-to-text": 500 .
  at async $fetchRaw2 (./node_modules/ofetch/dist/shared/ofetch.00501375.mjs:256:14)  
  at async $fetch2 (./node_modules/ofetch/dist/shared/ofetch.00501375.mjs:261:15)  
  at fetchOptions (./node_modules/nuxt-og-image/dist/runtime/nitro/utils.mjs:60:19)  
  at fetchOptionsCached (./node_modules/nuxt-og-image/dist/runtime/nitro/utils.mjs:55:19)  
  at <anonymous> (./node_modules/nuxt-og-image/dist/runtime/nitro/middleware/og.png.mjs:17:19)  
  at async Object.handler (./node_modules/h3/dist/index.mjs:1630:19)  
  at async Server.toNodeHandle (./node_modules/h3/dist/index.mjs:1840:7)
harlan-zw commented 11 months ago

Thanks for the issue, seems to be fixed in 3.0.0-rc.3.

Let me know if you have any issues with it.