image icon indicating copy to clipboard operation
image copied to clipboard

Usage with NuxtHub

Open larrasu opened this issue 2 months ago • 1 comments

Please advise if this is the best way to use NuxtImg with NuxtHub. Basically, I added route rules for the blob server route and @nuxt/image alias. It works. but I want to know if there's a better way and/if this should be added on the docs.

// nuxt.config.ts
export default defineNuxtConfig({
  routeRules: {
    '/blob/**': { ssr: false },
  },
  image: {
    domains: ['localhost:3000'],
    alias: {
      images: 'http://localhost:3000/blob',
    },
  },
})
// server/routes/blob/[...pathname].get.ts
export default eventHandler(async (event) => {
  const { pathname } = getRouterParams(event)

  if (!pathname) {
    return createError({
      statusCode: 404,
      statusMessage: 'Not Found',
    })
  }

  setHeader(event, 'Content-Security-Policy', 'default-src \'none\';')
  return hubBlob().serve(event, pathname)
})

larrasu avatar Oct 18 '25 23:10 larrasu

@danielroe @atinux We would love a clarification on this. Been struggling with this for way too long.

Thank you @larrasu for raising this up

therealokoro avatar Nov 07 '25 19:11 therealokoro