{"id":15432877,"url":"https://github.com/simonw/datasette-cors","last_synced_at":"2025-07-09T03:09:48.048Z","repository":{"id":62566738,"uuid":"195696804","full_name":"simonw/datasette-cors","owner":"simonw","description":"Datasette plugin for configuring CORS headers","archived":false,"fork":false,"pushed_at":"2024-04-12T03:21:37.000Z","size":19,"stargazers_count":11,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-27T08:21:15.156Z","etag":null,"topics":["datasette","datasette-io","datasette-plugin"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-07T21:03:11.000Z","updated_at":"2024-04-08T16:23:49.000Z","dependencies_parsed_at":"2024-04-12T04:40:36.523Z","dependency_job_id":null,"html_url":"https://github.com/simonw/datasette-cors","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"350fb79d10083b6657ef9812b12525595b0adbd3"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/simonw/datasette-cors","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fdatasette-cors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fdatasette-cors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fdatasette-cors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fdatasette-cors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonw","download_url":"https://codeload.github.com/simonw/datasette-cors/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fdatasette-cors/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262753016,"owners_count":23358879,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["datasette","datasette-io","datasette-plugin"],"created_at":"2024-10-01T18:28:57.852Z","updated_at":"2025-07-09T03:09:48.031Z","avatar_url":"https://github.com/simonw.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# datasette-cors\n\n[![PyPI](https://img.shields.io/pypi/v/datasette-cors.svg)](https://pypi.org/project/datasette-cors/)\n[![Tests](https://github.com/simonw/datasette-cors/actions/workflows/test.yml/badge.svg)](https://github.com/simonw/datasette-cors/actions/workflows/test.yml)\n[![Changelog](https://img.shields.io/github/v/release/simonw/datasette-cors?include_prereleases\u0026label=changelog)](https://github.com/simonw/datasette-cors/releases)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/datasette-cors/blob/main/LICENSE)\n\nDatasette plugin for configuring CORS headers, based on [asgi-cors](https://github.com/simonw/asgi-cors).\n\nYou can use this plugin to allow JavaScript running on an allowlisted set of domains to make `fetch()` calls to the JSON API provided by your Datasette instance.\n\n## Installation\n```bash\ndatasette install datasette-cors\n```\n## Configuration\n\nYou need to add some plugin configuration for this plugin to take effect.\n\nTo allowlist specific domains, use this:\n\n```json\n{\n    \"plugins\": {\n        \"datasette-cors\": {\n            \"hosts\": [\"https://www.example.com\"]\n        }\n    }\n}\n```\nThis affects the `access-control-allow-origin` header.\n\nYou can also allowlist host patterns like this:\n\n```json\n{\n    \"plugins\": {\n        \"datasette-cors\": {\n            \"host_wildcards\": [\"https://*.example.com\"]\n        }\n    }\n}\n```\n\nTo allow all origins, use:\n\n```json\n{\n    \"plugins\": {\n        \"datasette-cors\": {\n            \"allow_all\": true\n        }\n    }\n}\n```\nThis sets the `access-control-allow-origin` header to `*`.\n\nYou can specify allowed headers - with the `access-control-allow-headers` header - using the `headers` option:\n\n```json\n{\n    \"plugins\": {\n        \"datasette-cors\": {\n            \"allow_all\": true,\n            \"headers\": [\"Authorization\", \"Content-Type\"]\n        }\n    }\n}\n```\n\nTo allow specific HTTP methods with the `access-control-allow-methods` header, use the `methods` option:\n\n```json\n{\n    \"plugins\": {\n        \"datasette-cors\": {\n            \"allow_all\": true,\n            \"methods\": [\"GET\", \"POST\", \"OPTIONS\"]\n        }\n    }\n}\n```\n\nYou can set the `access-control-max-age` header using the `max_age` option:\n\n```json\n{\n    \"plugins\": {\n        \"datasette-cors\": {\n            \"allow_all\": true,\n            \"max_age\": 3600\n        }\n    }\n}\n```\n\n## Testing it\n\nTo test this plugin out, run it locally by saving one of the above examples as `metadata.json` and running this:\n```bash\ndatasette -m metadata.json\n```\nWith Datasette 1.0 use `-c config.json` instead, or try this:\n```bash\ndatasette -s plugins.datasette-cors.allow_all true\n```\n\nNow visit https://www.example.com/ in your browser, open the browser developer console and paste in the following:\n\n```javascript\nfetch(\"http://127.0.0.1:8001/_memory.json?sql=select+sqlite_version%28%29\").then(r =\u003e r.json()).then(console.log)\n```\n\nIf the plugin is working correctly, you will see the JSON response output to the console.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fdatasette-cors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonw%2Fdatasette-cors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fdatasette-cors/lists"}