[SOLVED] Content Delivery API requests to HTTPS re...
# help-with-umbraco
j
I'm running into issues when making calls to the Content Delivery API (https://localhost:44364/umbraco/delivery/api/v1/content) on the HTTPS port - the HTTP port ( http://localhost:9858/[...]) works just fine. I'm making the
fetch
call with Astro but want to check that it's not an Umbraco issue before asking Astro (the joys of not knowing where the problem lies). Some details: - Running both Umbraco and Astro locally - Calling a
fetch
to HTTP endpoint works fine - Calling a
fetch
to HTTPS endpoint returns the Fetch Failed error (image provided) - In
appsettings.json
I have Umbraco.CMS.Global.UseHttps set to
true
(unsure if relevant) - Umbraco version 13.2.0, Windows 11 - It's a Thursday When using Postman I can successfully make the API call to the HTTPS endpoint, but receive a cautionary "Unable to verify the first certificate" (image provided). The HTTP endpoint is successful and has no caution. Having just tried a basic JS query I'm actually getting a CORS error, so it might be that. If that's the case, how should I set-up CORS policies for the Content Delivery API?
Copy code
html
<script>
  fetch("https://localhost:44364/umbraco/delivery/api/v1/content")
    .then((response) => response.json())
    .then((data) => console.log(data));
</script>
Console:
Copy code
Access to fetch at 'https://localhost:44364/umbraco/delivery/api/v1/content' from origin 'http://localhost:5500' has been blocked by CORS policy: 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
Thanks in advance! Rich https://cdn.discordapp.com/attachments/1217931605331411037/1217931606099103755/error-img.png?ex=6605d232&is=65f35d32&hm=b2d76acb58522f16e5b71fec978dc1e57472e8febdd0c815d7b7bd053aea3184& https://cdn.discordapp.com/attachments/1217931605331411037/1217931606359146646/image.png?ex=6605d233&is=65f35d33&hm=8721080b581a52ff905c586cc6d77b35837bece5db3880536ddc2c3cef72ea3c&
Ah, it might be working through a classic Paul Seal blinder, will test that now: https://codeshare.co.uk/blog/how-to-set-up-a-cors-policy-in-umbraco-12/
Alas no, sorted the CORS, fetch fail still the same.
Ah... so it might just be a case of needing to use the http endpoint for local dev anyway. I'm v new to this side of things but interesting to know. https://letsencrypt.org/docs/certificates-for-localhost/
After re-reading Kenn's [blog post](https://kjac.dev/posts/jamstack-for-free-with-azure-and-cloudflare/) I found that you need to set
NODE_TLS_REJECT_UNAUTHORIZED=0
to stop Node.js from rejecting self-signed SSL certificates locally. Kenn's repo has all the answers, specifically around using
.env.development
and
astro.config.mjs
to support local dev. https://github.com/kjac/UmbracoAzureCloudflare
11 Views