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
Enable CORS access from JavaScript on other domains #24
Labels
enhancement
New feature or request
Comments
I'm going to enable CORS by default - if you want to disable it you can use a plugin setting. |
Some test HTML - pasted into http://htmledit.squarefree.com/ (has to be an HTTP site because HTTPS cannot make CORS requests to localhost): <textarea></textarea>
<script>
fetch('http://127.0.0.1:8009/graphql/til', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: '{ til { totalCount } }' }),
})
.then(res => res.json())
.then(res => document.getElementsByTagName('textarea')[0].value = JSON.stringify(res.data));
</script> |
This works! Demo: https://iridescent-neat-wolfberry.glitch.me/ fetch('https://datasette-graphql-demo.datasette.io/graphql', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: '{ repos { totalCount } }' }),
})
.then(res => res.json())
.then(res => document.getElementById('num').innerHTML = res.data.repos.totalCount); |
simonw
added a commit
to simonw/covid-19-datasette
that referenced
this issue
Aug 6, 2020
To get CORS support, refs simonw/datasette-graphql#24
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This requires extra CORS headers to allow the
content-type
header and thePOST
method.The text was updated successfully, but these errors were encountered: