cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Local approuter gives cors error while using a deployed service

banjade
Associate
Associate
0 Likes
1,575

Hello

I am trying to access the service of a CAP application from another CAP application both the applications are deployed. 

Current Environment is local, I have bounded the local approuter to the service which I need to use, when using directly via browser the API works. But when the UI application tries to call any API, it gives CORS issue.

Tried using extensions to disable/enable CORS but still no luck.

Directory structure for UI

banjade_0-1736150969691.png

xs-app.json for router

banjade_1-1736151058062.png

we have CORS middleware in service layer as well

banjade_2-1736151123488.png

When the manifest is being loaded gives cors

banjade_3-1736151184700.png

 

 

 

 

Accepted Solutions (0)

Answers (1)

Answers (1)

Dinu
Active Contributor
0 Likes

This is the issue:

"The url which gives the error is localhost:5000/{serviceRoute} the one that calls is localhost:4004"

Change your UI application to only make requests the same origin as it is served from. Let approuter which serves it route the requests to the correct url/destination. 

banjade
Associate
Associate
0 Likes

when I try to make request to port 4004 where the main application is running the service request give 404. in approuter I am calling the correct destination which is a deployed service on BTP

"autoService": {
"type": "OData",
"settings": {
"annotations": [],
"odataVersion": "2.0"
}
}
this is what datasource looks like in manifest
Dinu
Active Contributor
0 Likes

You should not add hostname in the uri property of data source. Typical CAP (development) server setup only allows for requests to one (the same) CAP application. If you want to connect to two CAP application you need to access the application using a reverse proxy that will route the requests correctly; either use approuter or use backend proxy in Fiori/UI5 tools.