UNPKG

@nuxt/image

Version:

Nuxt Image Module

23 lines (22 loc) 1.02 kB
import { fileURLToPath } from "node:url"; import { createIPX, createIPXH3Handler, ipxFSStorage, ipxHttpStorage } from "ipx"; import { lazyEventHandler, useBase } from "h3"; import { isAbsolute } from "pathe"; import { useRuntimeConfig } from "#imports"; export default lazyEventHandler(() => { const opts = useRuntimeConfig().ipx || {}; const fsDir = opts?.fs?.dir ? (Array.isArray(opts.fs.dir) ? opts.fs.dir : [opts.fs.dir]).map((dir) => isAbsolute(dir) ? dir : fileURLToPath(new URL(dir, import.meta.url))) : void 0; const fsStorage = opts.fs?.dir ? ipxFSStorage({ ...opts.fs, dir: fsDir }) : void 0; const httpStorage = opts.http?.domains ? ipxHttpStorage({ ...opts.http }) : void 0; if (!fsStorage && !httpStorage) { throw new Error("IPX storage is not configured!"); } const ipxOptions = { ...opts, storage: fsStorage || httpStorage, httpStorage }; const ipx = createIPX(ipxOptions); const ipxHandler = createIPXH3Handler(ipx); return useBase(opts.baseURL, ipxHandler); });