unjs / ipx

🖼️ High performance, secure and easy-to-use image optimizer.
MIT License
1.54k stars 61 forks source link

IPX Forbidden error V0.7.2 #43

Closed thomas4Bitcraft closed 3 years ago

thomas4Bitcraft commented 3 years ago

I'm using nuxt/image with the custom IPX Server middleware and always get an IPX Forbidden error although the domain is set in

const ipx = createIPX({
  domains: ['...'],
})

As soon as I downgrade to 0.6.7 everything is working fine. Was there a bigger change since 0.6.7?

pi0 commented 3 years ago

Hi @thomas4Bitcraft. Do you mind sharing domains values you use and maybe a URL to check?

Regarding changes, you can check changelog but I would recommend not sticking with 0.6.x if possible :)

thomas4Bitcraft commented 3 years ago

Sure.

const ipx = createIPX({
  domains: ['xxx'],
})

Nuxt: http://localhost:3000/_ipx/https://xxx/media/course_images/xxx.jpg?h=160&fit=cover Image: https://xxx/media/course_images/xxx.jpg

pi0 commented 3 years ago

Hmm seems odd. localhost link seems from an old version of ipx/image since in latest ipx@0.7.x and image@v0.5.x versions, we use operations after _ipx like _ipx/h_160,fit_cover/https://..... Can you please check all versions are latest and recreate package-lock.json or yarn.lock?

thomas4Bitcraft commented 3 years ago

Tried to remove node_modules + package.lock, clear cache and using version:

"@nuxt/image": "^0.5.0",
"ipx": "^0.7.2",

still the same. This is my nuxt.config:

image: {
    domains: [process.env.BASE_URL],
    presets: {
      base: {
        baseURL: `/_ipx/${process.env.BASE_URL}/`
      }
    }
  },

  serverMiddleware: {
    '/_ipx': '~/server/middleware/ipx.js'
  },

and this the middleware as a whole:

import { createIPX, createIPXMiddleware } from 'ipx'

const ipx = createIPX({
  domains: ['xxx'],
})

export default createIPXMiddleware(ipx)

nuxt/image also seems to use 0.6.4 atm (from package.lock)

"@nuxt/image": {
      "version": "0.5.0",
      "resolved": "https://registry.npmjs.org/@nuxt/image/-/image-0.5.0.tgz",
      "integrity": "sha512-vajBLMj3cW9U+MkXAR3f2hDl/Imj/jdnrL2mlw6phcuApWG2R4hwntAWyr96JzBMhoSK9tv2dJTGx4k9VKK9vA==",
      "requires": {
        "consola": "^2.15.3",
        "defu": "^5.0.0",
        "fs-extra": "^10.0.0",
        "hasha": "^5.2.2",
        "image-meta": "^0.0.1",
        "ipx": "^0.6.4",
        "is-https": "^4.0.0",
        "lru-cache": "^6.0.0",
        "node-fetch": "^2.6.1",
        "p-limit": "^3.1.0",
        "rc9": "^1.2.0",
        "requrl": "^3.0.2",
        "semver": "^7.3.5",
        "ufo": "^0.7.7",
        "upath": "^2.0.1"
      },
pi0 commented 3 years ago

You are right! IPX upgrade wasn't released... Can you pleas try with @nuxt/image@0.6.0 and ipx@0.8.0?

thomas4Bitcraft commented 3 years ago

Perfect - everything works now 🙌 Thank you for the very fast response!