GoogleChromeLabs / carlo

Web rendering surface for Node applications
Apache License 2.0
9.32k stars 309 forks source link

How to make localhost node-GraphQL request from index.html? #156

Closed sudhakar3697 closed 5 years ago

sudhakar3697 commented 5 years ago

Code:

<script> var x="abc"; const query = { platform } fetch('http://localhost:4000/apiv1', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ query }) }) .then(r => r.json()) .then(data => {console.log('Response:', data);document.write(data.data.platform)}); </script>

Console Error:

Failed to load resource: the server responded with a status of 405 (Method Not Allowed) index.html:1 Access to fetch at 'http://localhost:4000/apiv1' from origin 'https://domain' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: 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.

index.html:1 Uncaught (in promise) TypeError: Failed to fetch 2localhost:4000/apiv1:1 Failed to load resource: the server responded with a status of 405 (Method Not Allowed)

index.html:1 Access to fetch at 'http://localhost:4000/apiv1' from origin 'https://domain' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: 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.

index.html:1 Uncaught (in promise) TypeError: Failed to fetch