withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.98k stars 2.5k forks source link

_image endpoint returning a 404 for local images #8735

Closed jdtjenkins closed 1 year ago

jdtjenkins commented 1 year ago

Astro Info

Astro                    v3.2.2
Node                     v18.16.1
System                   Windows (x64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             @astrojs/tailwind
                         @astrojs/svelte
                         @storyblok/astro

If this issue only occurs in one browser, which browser is a problem?

Chrome

Describe the Bug

After enabling the Vite Basic SSL plugin (@vitejs/plugin-basic-ssl) and serving my local dev on https my images that are stored within the src folder are returning a 404 when trying to load from the _image endpoint.

What's the expected result?

The endpoint should return a 200 and the image should show.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-x9jtgg https://codesandbox.io/p/sandbox/condescending-mirzakhani-8qpy34 ------ I have added a stackblitz link that won't run dev and a codesandbox that will run dev but not connect! So I didn't know what to do. They both break because of the ssl plugin but the code is there

Participation

jdtjenkins commented 1 year ago

Also forgot to include this in the issue but my image and vite config are here:

// astro.config.mjs

{
...,
image: {
    domains: [
      'localhost',
      'storyblok.com',
    ],
    remotePatterns: [
      {
        protocol: 'https',
        hostname: '**.storyblok.com',
      },
      {
        protocol: 'https',
        hostname: 'localhost',
        port: '4321',
        pathname: '/*',
      },
    ],
  },
  vite: {
    plugins: [
      basicSsl()
    ],
    server: {
      https: true,
    },
  }
}
Princesseuh commented 1 year ago

Tried the repro locally and everything works for me on macOS, so this could be a Windows issue maybe

andrejilderda commented 1 year ago

@Princesseuh Could it be that this line: astro/packages/astro/src/assets/endpoint/node.ts at 90d70eb7c4ceddf7246e338100e01de7dc8756f6 · withastro/astro

Needs a similar workaround for Windows as this one: https://github.com/unix/astro-https-image-endpoint/pull/2

Princesseuh commented 1 year ago

@Princesseuh Could it be that this line: astro/packages/astro/src/assets/endpoint/node.ts at 90d70eb7c4ceddf7246e338100e01de7dc8756f6 · withastro/astro

Needs a similar workaround for Windows as this one: https://github.com/unix/astro-https-image-endpoint/pull/2

Ah yes, probably. I might've gotten tripped up with the fact that this previously only handled URLs and not file paths