image
image copied to clipboard
Usage with NuxtHub
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)
})
@danielroe @atinux We would love a clarification on this. Been struggling with this for way too long.
Thank you @larrasu for raising this up