Hello SAP Community,
I have been wrestling with a CORS error for a while now and have tried to comb through the community forums and sap documentation to figure it out, but just can’t get there. I am missing something.
The error I am getting is “Access to fetch at ‘https://<srv>.com/rest/corstest/go’ from origin ‘https://<app>.com’ 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.”
Here is the Github link to my CAP project: https://github.com/dustinself/try-cors
I am not trying to run it “locally” but rather deploy the project to Cloud Foundry and run it from there.
This is a really simple application where I have set up a cds service that has a rest endpoint that simply returns “Hello, World!”. I then have an app configured with approuter that serves up a simple index.html page that calls the endpoint when the page loads. I also have xsuaa enabled for authentication purposes. I have defined CORS in the mta.yaml like this:
– name: try-cors-app
type: approuter.nodejs
path: app/
parameters:
keep-existing-routes: true
disk-quota: 256M
memory: 256M
requires:
– name: srv-api
group: destinations
properties:
name: srv-api
url: ~{srv-url}
forwardAuthToken: true
– name: try-cors-auth
properties:
CORS:
– uriPattern: .
allowedOrigin:
– host: “*”
Once I deploy, I can see the environment variable (under User-Provided Variables) for the app:
CORS | [ { “allowedOrigin” : [ { “host” : “*” } ], “uriPattern” : “.” } ] |
If you are an expert who has done this before, can you please take a look and let me know what I am missing? I would really appreciate the help.
Thanks,
Dustin