Datasette plugin for configuring CORS headers
Project description
datasette-cors
Datasette plugin for configuring CORS headers, based on https://github.com/simonw/asgi-cors
You can use this plugin to allow JavaScript running on a whitelisted set of domains to make fetch()
calls to the JSON API provided by your Datasette instance.
Installation
pip install datasette-cors
Configuration
You need to add some configuration to your Datasette metadata.json
file for this plugin to take effect.
To whitelist specific domains, use this:
{ "plugins": { "datasette-cors": { "hosts": ["https://www.example.com"] } } }
You can also whitelist patterns like this:
{ "plugins": { "datasette-cors": { "host_wildcards": ["https://*.example.com"] } } }
Testing it
To test this plugin out, run it locally by saving one of the above examples as metadata.json
and running this:
$ datasette --memory -m metadata.json
Now visit https://www.example.com/ in your browser, open the browser developer console and paste in the following:
fetch("http://127.0.0.1:8001/:memory:.json?sql=select+sqlite_version%28%29").then(r => r.json()).then(console.log)
If the plugin is running correctly, you will see the JSON response output to the console.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Built Distribution
Hashes for datasette_cors-0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7cb6425d3b2806b3bcde72c23fc84f5b2402517d8655e0cd63cf0d5ef371f9a |
|
MD5 | 0c0f962f049abc5187feb658b0038915 |
|
BLAKE2-256 | 1eda85322a300c5503284c652acb0b067cdf293a1ba9fc90fa656eee987f1987 |