Local image resolution from external dns address #6128
Description
What version of astro
are you using?
1.6.13
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
yarn
What operating system are you using?
Mac
Describe the Bug
I am developing a website on my mac system, for testing purposes I use my phone to browse it in my home wifi. My modem is configured to resolve my mac-hostname to it's address, so inside my phone I open for example http://arash-mac:3000
. But inside my mac, I have other dns servers configured, which means it cannot resolve it's own address. Inside @astrojs/image
there's a line that tries to resolve local images through whatever hostname that they are requested through. In this case, it tries to resolve http://arash-mac:3000/_image/etc
instead of http://localhost:3000/_image/etc
.
At following line of code, when isRemoteImage
returns false, url.origin
is used as is, which in this complex scenario cannot be resolved into local machine. I did fix it by patching it into new URL(transform.src, 'http://localhost:' + url.port)
, however I believe the code design is problematic on a different level (trying to fetch local images through http queries).
https://github.com/withastro/astro/blob/main/packages/integrations/image/src/endpoint.ts#L33
Link to Minimal Reproducible Example
not applicable
Participation
- I am willing to submit a pull request for this issue.