Search code examples
javascriptnode.jsangularhttp-proxy

Angular proxy.conf


I'm trying to send all my requests from localhost:4200 to localhost:3000 but I can't achieve what I want. My Node.js server uses localhost:3000/login and localhost:3000/register. In the front end, I do

http.post('/login', {whatever})

but I cant get the request to my server without sending it to http://localhost:3000/login. Here is my proxy.conf.json

{
  "/login": { // I tried with "*" and ""
  "target": "http://localhost:3000",
  "secure": false,
  "changeOrigin": true
  }
}

I want all the requests I do to go to localhost:3000. Everywhere I see that people put /api prefix, but this will send it to localhost:3000/api/loginand I want just localhost:3000/login


Solution

  • mine looks like this /ProjectREST is the backend prefix to all URL ie its the rootProject.name(in graddle) of my backend server.

    {
      "/ProjectREST": {
         "target":  {
           "host": "localhost",
           "protocol": "http:",
           "port": 8090
         },
         "secure": false,
         "changeOrigin": true,
         "logLevel": "debug"
       }
     }
    

    I access the server via "/ProjectREST/register" requests.