Home > Software engineering >  Whats Wrong With My proxy config file For Multiple Targets
Whats Wrong With My proxy config file For Multiple Targets

Time:03-25

I'm trying to create a proxy config file for multiple targets it does not seem to be working. I have one in place that is working fine for diverting my URL to the back end. Upon my research I'm aware that you cannot have multiple config files but you can create a proxy config for multiple targets, I'm also aware you would use the js extension rather than the json extension. I'm aware where to add it in the angular json file. My issue here is that it is not working the reason I say this is because I'm getting not found on the path that was working before. I have included the proxy config file json which I was using initially and the proxy config js I'm trying to create. I code I'm using was found while doing some research on multiple targets and sort of followed the pattern from the original proxy file. Can someone please help me.

proxy.config.json file

{
"/api/*": {
    "target": "http://localhost:3000",
    "logLevel": "debug",
    "pathRewrite": {
      "^/api": ""
    }
    
    
  }
}

proxy.config.js

const TARGET_URL1 = "http://localhost:3000";
const TARGET_URL2 = "http://localhost:4100";
   const PROXY_CONFIG = [
      
      {
          context:[
              "/api"
          ],
          target: TARGET_URL1,
          logLevel: "debug"
      },
      {
          context: [
              "/users"
          ],
          target: TARGET_URL2,
          logLevel: "debug"
      },

   ];

Greatly Appreciated

CodePudding user response:

I'm not sure how the js config works but for the JSON config file you can use:

{
    "/api/*": {
        "target": "http://localhost:3000",
        "logLevel": "debug",
        "pathRewrite": {
            "^/api": ""
        }
    },
    "/users/*": {
        "target": "http://localhost:4100",
        "logLevel": "debug",
        "pathRewrite": {
            "^/users": ""
        }
    }
}
  • Related