An option to turn off CORS for HTTP
gavvvr opened this issue · comments
Hello! Thank you for this project.
I used it for comparing different requests I was making from vanilla fetch
API and through a proxy service I do not have direct control over.
The problem I faced with was a CORS, because I worked with Electron-based app (which is a browser under the hood):
Access to fetch at 'http://localhost:8080/' from origin 'app://obsidian.md' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
To fix the error I've added the following line to serveHTTP
:
wr.Header().Set("Access-Control-Allow-Origin", "*")
wr.Header().Set("Access-Control-Allow-Methods", "*")
wr.Header().Set("Access-Control-Allow-Headers", "*")
Consider adding those headers with an option you can configure on startup.
Thanks for the request! I have added a way to accomplish this in v0.3.6 by allowing configuration of arbitrary headers.