Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local image assets not found when using https:// #8395

Closed
1 task
andrejilderda opened this issue Sep 4, 2023 · 9 comments · Fixed by #8698
Closed
1 task

Local image assets not found when using https:// #8395

andrejilderda opened this issue Sep 4, 2023 · 9 comments · Fixed by #8698
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: assets Related to the Assets feature (scope)

Comments

@andrejilderda
Copy link

Astro Info

Astro                    v3.0.8
Node                     v18.17.1
System                   macOS (arm64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             none

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

No response

Describe the Bug

Astro image assets return a 404 Not Found when running astro dev with Vite's (dev) server set to https: true.

The reproduction is using @vitejs/plugin-basic-ssl, which is Vite's recommended way of running a dev server with https.

I also tried running the dev server without https and proxy the requests separately, but this results in the same error (if needed I can provide the reproduction for this as well).

What's the expected result?

I expected the image to display properly.

Link to Minimal Reproducible Example

https://github.com/andrejilderda/astro-local-https-assets-issue

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Sep 4, 2023
@Princesseuh Princesseuh added - P3: minor bug An edge case that only affects very specific usage (priority) feat: assets Related to the Assets feature (scope) and removed needs triage Issue needs to be triaged labels Sep 5, 2023
@Princesseuh
Copy link
Member

This is similar to #6128 and #5699

I'm thinking maybe we should use fs in dev at least. It's annoying because of the code duplication it requires, but might be unfortunately needed.

@ak-en
Copy link

ak-en commented Sep 7, 2023

Adding my vote to this issue. We need HTTPS on the web frontend due to CORS (server API being called only allows https), and so having this capability would definitely be very useful. Right now, we have to run the API related components with images showing as broken and then test the images separately by disabling https.

@andrejilderda
Copy link
Author

@ak-en This is very similar to my case. 👍

@alecdiaz1
Copy link

Also having this issue with a similar case to @ak-en. Trying to use Storyblok's visual editor with Astro but Storyblok requires HTTPS.

@unix
Copy link

unix commented Sep 26, 2023

I created a repo (astro-https-image-endpoint) to solve this issue, maybe it will help you guys out.

Now it works fine for me locally and will be automatically disabled in production. (If there are any issues with deployment, you can simply comment out the configuration.)

// astro.config.mjs
import imageEndpoint from 'astro-https-image-endpoint'

export default defineConfig({
  // ... your configs
  image: {
    endpoint: imageEndpoint(import.meta.env.DEV),
  },
})

cc @alecdiaz1 @ak-en @andrejilderda

@Princesseuh
Copy link
Member

I created a repo (astro-https-image-endpoint) to solve this issue, maybe it will help you guys out.

Now it works fine for me locally and will be automatically disabled in production. (If there are any issues with deployment, you can simply comment out the configuration.)

// astro.config.mjs
import imageEndpoint from 'astro-https-image-endpoint'

export default defineConfig({
  // ... your configs
  image: {
    endpoint: imageEndpoint(import.meta.env.DEV),
  },
})

cc @alecdiaz1 @ak-en @andrejilderda

Awesome work using 3.1's new feature for setting a custom endpoint! I made it exactly for this purpose. Hoping to build a similar solution in Astro itself very soon

@ak-en
Copy link

ak-en commented Sep 26, 2023

I created a repo (astro-https-image-endpoint) to solve this issue, maybe it will help you guys out.

Now it works fine for me locally and will be automatically disabled in production. (If there are any issues with deployment, you can simply comment out the configuration.)

// astro.config.mjs
import imageEndpoint from 'astro-https-image-endpoint'

export default defineConfig({
  // ... your configs
  image: {
    endpoint: imageEndpoint(import.meta.env.DEV),
  },
})

cc @alecdiaz1 @ak-en @andrejilderda

Will try it out!

@andrejilderda
Copy link
Author

✨ Works like a charm, thanks a lot @unix . Great workaround for now! Feel free to close this issue @Princesseuh .

@ak-en
Copy link

ak-en commented Sep 27, 2023

@unix, I tried it today but did not work. Here is what I did:

My vite config is as below (the key and cert files referred have been generated and work fine to run locally with https):

vite: {
    server: {
      host: "0.0.0.0",
      port: 3000,
      https: {
          key: "./example.com+5-key.pem",
          cert: "./example.com+5.pem",
      },
}

Does the host='0.0.0.0' have any incompatibility with imageEndpoint?
Is imageEndpoint only expected to work with the method to configure https shown at https://github.com/unix/astro-https-image-endpoint#how-to-set-https-in-astro?

I am on node 18.17.1 - is a newer version needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: assets Related to the Assets feature (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants