Closed murali474 closed 4 years ago
Use this snippet in your React code, which will give you the base URL for your application:
const basePath = window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
Good luck with your project!
Hi ,
First of all, thanks for the reply .I think I need to reexplain my issue here .
I will deploy my UI war at one node and my back end services at another node or same node .so, now I should read host and port of my server where my backend services deployed . So how can I read them at deployment time rather build stage
Thanks, Murali.
On Mon, Aug 3, 2020, 7:41 PM Eirik Sletteberg <notifications@github.com wrote:
Use this snippet in your React code, which will give you the base URL for your application:
const basePath = window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
Good luck with your project!
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eirslett/frontend-maven-plugin/issues/923#issuecomment-668044685, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALDFQWKWQ6NH5R5ZMPWRI2LR63AQVANCNFSM4PTKTFYQ .
Ok so you have a UI .war, which is probably a Spring app? I suggest that you make a REST endpoint in your UI war/app/servlet, for example /config.json
, and in the response, you return configuration for the frontend - like for example the backend URLs.
Thanks Eirslett, this approach helped me .
Regards, Murali
On Mon, Aug 3, 2020 at 10:03 PM Eirik Sletteberg notifications@github.com wrote:
Ok so you have a UI .war, which is probably a Spring app? I suggest that you make a REST endpoint in your UI war/app/servlet, for example /config.json, and in the response, you return configuration for the frontend - like for example the backend URLs.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eirslett/frontend-maven-plugin/issues/923#issuecomment-668119845, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALDFQWJRHA3HYASKEDB6FS3R63RG5ANCNFSM4PTKTFYQ .
Hi @eirslett , Sorry to reopen the conversation.
so, is window.location code part in react code works if configure my application with Load balancer. will the window.location.hostname give us the actual node details or LoadBalancer details?
Currently i am using this plugin to convert react app to spring boot war. Now I need to retrieve/supply backend host and port urls from properties file and use in react ui code.
I knew the process for general spring boot application and could not find any documentation/reference related property externalization in case of react based spring boot war.
Quick responses are much appreciated and Please help me in this.