-
-
Notifications
You must be signed in to change notification settings - Fork 697
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
Plugin for allowing CORS from specified hosts #454
Comments
Since I want the option to store more than one host, I don't think this should be a command-line option or a Maybe this should be a plugin? That way the
This could be implemented easily on top of ASGI #272. (It should probably raise an exception on startup if any of the |
Also worth considering: |
I really like the idea of this as a plugin, because it will provide a great example of an ASGI plugin including how to build unit tests against Datasette plugins which actually start up a Datasette server and run some requests through it. |
I built a new ASGI middleware component for CORS headers which I can use to implement this: https://pypi.org/project/asgi-cors/ and https://github.com/simonw/asgi-cors |
I built and shipped this back in July: https://github.com/simonw/datasette-cors |
It would be useful if Datasette could be configured to allow CORS requests from one or more origins, as opposed to only allowing either none or
"*"
.This is slightly tricky because the
Access-Control-Allow-Origin: https://foo.example
header is only allowed to return one value per request - and according to https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS "The Access-Control-Allow-Origin header should contain the value that was sent in the request's Origin header."This means the application code needs to have a whitelist of allowed hosts and code that dynamically changes the outgoing
Access-Control-Allow-Origin
header based on theOrigin
header from the incoming request.The text was updated successfully, but these errors were encountered: