angular proxy the same endpoint with different domains











up vote
0
down vote

favorite












Hey I have a angular client which wants to proxy the http request to different api servers. The issue is that I have two different servers:

10.0.0.1:8080
10.0.0.2:8080

Both the servers has the same endpoint, let's say, /api/v1/

When I call a http request to /api/v1/ how do I specify which server to go ?

I dont' want to call domain plus endpoint directly. Because that may raise the CORS problem.



------------------------------------------update-----------------------------------------------

Inspired by @Arne, I decide to use the following method:



"/server1": {
"target": "http://10.0.0.1:8080",
"secure": false,
"pathRewrite": {"^/server1" : ""}
},
"/server2": {
"target": "http://10.0.0.2:8080",
"secure": false,
"pathRewrite": {"^/server2" : ""}
}


every time I call a request /server1/api/v1/, it'll be proxied to 10.0.0.1:8080/api/v1










share|improve this question




























    up vote
    0
    down vote

    favorite












    Hey I have a angular client which wants to proxy the http request to different api servers. The issue is that I have two different servers:

    10.0.0.1:8080
    10.0.0.2:8080

    Both the servers has the same endpoint, let's say, /api/v1/

    When I call a http request to /api/v1/ how do I specify which server to go ?

    I dont' want to call domain plus endpoint directly. Because that may raise the CORS problem.



    ------------------------------------------update-----------------------------------------------

    Inspired by @Arne, I decide to use the following method:



    "/server1": {
    "target": "http://10.0.0.1:8080",
    "secure": false,
    "pathRewrite": {"^/server1" : ""}
    },
    "/server2": {
    "target": "http://10.0.0.2:8080",
    "secure": false,
    "pathRewrite": {"^/server2" : ""}
    }


    every time I call a request /server1/api/v1/, it'll be proxied to 10.0.0.1:8080/api/v1










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Hey I have a angular client which wants to proxy the http request to different api servers. The issue is that I have two different servers:

      10.0.0.1:8080
      10.0.0.2:8080

      Both the servers has the same endpoint, let's say, /api/v1/

      When I call a http request to /api/v1/ how do I specify which server to go ?

      I dont' want to call domain plus endpoint directly. Because that may raise the CORS problem.



      ------------------------------------------update-----------------------------------------------

      Inspired by @Arne, I decide to use the following method:



      "/server1": {
      "target": "http://10.0.0.1:8080",
      "secure": false,
      "pathRewrite": {"^/server1" : ""}
      },
      "/server2": {
      "target": "http://10.0.0.2:8080",
      "secure": false,
      "pathRewrite": {"^/server2" : ""}
      }


      every time I call a request /server1/api/v1/, it'll be proxied to 10.0.0.1:8080/api/v1










      share|improve this question















      Hey I have a angular client which wants to proxy the http request to different api servers. The issue is that I have two different servers:

      10.0.0.1:8080
      10.0.0.2:8080

      Both the servers has the same endpoint, let's say, /api/v1/

      When I call a http request to /api/v1/ how do I specify which server to go ?

      I dont' want to call domain plus endpoint directly. Because that may raise the CORS problem.



      ------------------------------------------update-----------------------------------------------

      Inspired by @Arne, I decide to use the following method:



      "/server1": {
      "target": "http://10.0.0.1:8080",
      "secure": false,
      "pathRewrite": {"^/server1" : ""}
      },
      "/server2": {
      "target": "http://10.0.0.2:8080",
      "secure": false,
      "pathRewrite": {"^/server2" : ""}
      }


      every time I call a request /server1/api/v1/, it'll be proxied to 10.0.0.1:8080/api/v1







      angular proxy






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 at 3:45

























      asked Nov 21 at 22:01









      debuglife

      12




      12
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          You could proxy any alias in whatever server you're using it's proxy config. So you could proxy /server1 to 10.0.0.1:8080/api/v1/ and /server2 to 10.0.0.2:8080/api/v1/. Which server are you using?






          share|improve this answer





















          • you mean give an alias /server1 to the server 10.0.0.1:8080 and rewrite the path right? just like this: rewrite /server1 with /api/v1/
            – debuglife
            Nov 22 at 3:12













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421066%2fangular-proxy-the-same-endpoint-with-different-domains%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          You could proxy any alias in whatever server you're using it's proxy config. So you could proxy /server1 to 10.0.0.1:8080/api/v1/ and /server2 to 10.0.0.2:8080/api/v1/. Which server are you using?






          share|improve this answer





















          • you mean give an alias /server1 to the server 10.0.0.1:8080 and rewrite the path right? just like this: rewrite /server1 with /api/v1/
            – debuglife
            Nov 22 at 3:12

















          up vote
          0
          down vote













          You could proxy any alias in whatever server you're using it's proxy config. So you could proxy /server1 to 10.0.0.1:8080/api/v1/ and /server2 to 10.0.0.2:8080/api/v1/. Which server are you using?






          share|improve this answer





















          • you mean give an alias /server1 to the server 10.0.0.1:8080 and rewrite the path right? just like this: rewrite /server1 with /api/v1/
            – debuglife
            Nov 22 at 3:12















          up vote
          0
          down vote










          up vote
          0
          down vote









          You could proxy any alias in whatever server you're using it's proxy config. So you could proxy /server1 to 10.0.0.1:8080/api/v1/ and /server2 to 10.0.0.2:8080/api/v1/. Which server are you using?






          share|improve this answer












          You could proxy any alias in whatever server you're using it's proxy config. So you could proxy /server1 to 10.0.0.1:8080/api/v1/ and /server2 to 10.0.0.2:8080/api/v1/. Which server are you using?







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 at 23:45









          Arne

          514212




          514212












          • you mean give an alias /server1 to the server 10.0.0.1:8080 and rewrite the path right? just like this: rewrite /server1 with /api/v1/
            – debuglife
            Nov 22 at 3:12




















          • you mean give an alias /server1 to the server 10.0.0.1:8080 and rewrite the path right? just like this: rewrite /server1 with /api/v1/
            – debuglife
            Nov 22 at 3:12


















          you mean give an alias /server1 to the server 10.0.0.1:8080 and rewrite the path right? just like this: rewrite /server1 with /api/v1/
          – debuglife
          Nov 22 at 3:12






          you mean give an alias /server1 to the server 10.0.0.1:8080 and rewrite the path right? just like this: rewrite /server1 with /api/v1/
          – debuglife
          Nov 22 at 3:12




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421066%2fangular-proxy-the-same-endpoint-with-different-domains%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Sphinx de Gizeh

          Dijon

          Guerrita