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

Add/modify Headers (CORS) #80

Closed
jcubic opened this issue Jul 18, 2023 · 8 comments · Fixed by #87
Closed

Add/modify Headers (CORS) #80

jcubic opened this issue Jul 18, 2023 · 8 comments · Fixed by #87
Labels
enhancement New feature or request

Comments

@jcubic
Copy link

jcubic commented Jul 18, 2023

Is your feature request related to a problem? Please describe.

I'm working on a blog that uses Giscus that allows to change theme by using custom CSS. In order to use this feature you need to put a full path to the CSS file when initializing the Giscus. So when using the path to the dev server I got a CORS error.

Describe the solution you'd like

CORS option for dev server

Describe alternatives you've considered

I was thinking of using a Chrome extension that enables CORS headers (like CORS everywhere) but the last time I checked an extension like this it was not working when CORS was needed.

Additional context

No response

@jcubic jcubic added the enhancement New feature or request label Jul 18, 2023
@craig552uk
Copy link

Not a fix, but you can hack in CORS support to the dev server by adding this to line 418 of node_modules/@11ty/eleventy-dev-server/server.js

res.setHeader("Access-Control-Allow-Origin", '*');

@jcubic
Copy link
Author

jcubic commented Feb 18, 2024

@craig552uk it looks exactly like a fix. If maintainers of Eleventy decide it fits into the project.

@uncenter
Copy link

@craig552uk the repository for that code is at https://github.com/11ty/eleventy-dev-server, you could raise a PR for that fix.

@zachleat zachleat transferred this issue from 11ty/eleventy Jun 18, 2024
@zachleat
Copy link
Member

Seems like a mechanism to add/modify headers would be useful! I don’t know that I’d want to Access-Control-Allow-Origin everything by default, but some kinda hook would be good!

@zachleat
Copy link
Member

Here’s an example of that happening in the code now (though this example is not user configurable)

res.setHeader("Content-Type", mime.getType("js"));

@jcubic
Copy link
Author

jcubic commented Jun 19, 2024

It should be simple to add headers to default options.

@craig552uk
Copy link

PR for my initial suggestion #81

I consider this to be a hack rather than a fix, as it's probably not desirable to add this to all responses.
I'd favour a hook (as @zachleat suggested) though don't have the time to work on it.

@zachleat zachleat changed the title Dev Server and CORS Add/modify Headers (CORS) Jun 19, 2024
@zachleat zachleat added this to the Eleventy Dev Server v2.0.3 milestone Sep 4, 2024
@zachleat
Copy link
Member

zachleat commented Sep 4, 2024

Shipping with Dev Server v2.0.3, core v3.0.0-beta.2 v3.0.0-alpha.19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants