0

I have a impolemented frontend in Node+Angular js and backend is running in Jetty exposing REST service.I want to send REST rquest from FE(Angular) to backend.when I am passing the complete URL to $http.get it works fine.However I want to mak it a configurable value so that any change in the URL/Port will not require me to change elsewhere apart from the configuration.Currently I am passing it as $http.post("http://localhost:8080/test/login/doStuff",dataObj) However I want to pass it as $http.post("/test/login/doStuff",dataObj) and automatically it should append http://localhost:8080.Can someone help me on this?

Thanks

2 Answers 2

1

CORS is used to enable the communication trust between two different hosts. For example if the front end and back-end hosted in two different servers (not in the same domain) requires CORS to communicate in between.
However, in your case, I do not see a valid case except they deployed apart as explained.
A web app always can communicate using relative paths as long as they are hosted in the same server.
If the app hosted inside /myApp folder, it can access other resources using /myApp/other-web-folders.
If you want to communicate outside domain, you always have to do it with the full url. Hope this clarifies your doubts.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply. I understand it. i want to make the url configurable.Is there any way that If I specify a relative url in the angular method then the other domain url will get appended?
You can devise a mechanism like this. Always seperate the URL to two parts. The host and the path. You can change the host if it requires to load from a separate domain accordingly. This is just a suggestion. However, you don't have to do anything at the Angular level to enable CORS as its happen at the web server level.
0

You can store the hostname in another variable and concat that with url

let host = "http://localhost:8080"

$http.post(host + "/test/login/doStuff", dataObj)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.