unjs / ipx

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

"Invalid URL" error on domains like: http.cat #79

Closed eggsy closed 2 years ago

eggsy commented 2 years ago

Hey! I believe this issue is meant to be here because I tried digging through the source of @nuxt/image-which led to nothing, and I found out that whatever is parsing the new URL() API from our @nuxt/image config.domains throws an Invalid URL error whenever the domain begins with a protocol-like string. For example, I use http.cat for my error pages and put a funny cat status there. After upgrading the image module today, I saw my app wasn't starting because of this error and I started digging, after 20 minutes of searching through compiled .cjs source files, I believe this issue is directly related to your module ipx and its createIPX middleware. Not sure though. But my code works right before that method is called. I also tried digging your source but couldn't find where my domain options reach. I will keep digging and will update this issue if I find more details. I hope this gets fixed.

image

eggsy commented 2 years ago

Actually, I just figured it out, it's because createHTTPSource maps through the domains only checking if they don't start with http as it's seen here, but what it should do instead is check whether it's a protocol so at least append : at the end of that, like http:. But then, if you pass an URL that starts with https: then it would convert it to http://https://domain.com or whatever. So, best approach would be to check both if it starts with http: or https:. Here you can see the result:

Well, I just realized that this part of the code seems to be removed from the source, but it's still there on my computer, that's weird. Maybe it's passed-somehow from the image module, but I have no idea. Tried running yarn upgrade but didn't work.

Edit: Well because what I'm looking for is compiled source code, it seems to be chunked into one middleware file with combined functions from ufo, I tried installing ufo to have latest changes to hasProtocol function because I see that now it's using regex instead of new URL as this is what I understand from here.

image

eggsy commented 2 years ago

any updates?