11

I have a project that uses angular as the front end and has a laravel API for the backend. I want to make use of ng serve's proxy live reloading:

ng serve --proxy-config proxy.config.js

Here is the proxy.config.js file:

const PROXY_CONFIG = {                             
  "/v2/*": {                                     
    "target": "http://local-laravel-api/",
    "secure": false,                           
    "pathRewrite": {                           
      "^/v2": "/v2"                            
    },                                         
    "logLevel": "debug", 
    "changeOrigin": true
  }
}

module.exports = PROXY_CONFIG;

The laravel API has auth. When I visit localhost:4200 I get "Not Authenticated" and that is because the auth cookie is not set in the browser when going through the proxy.

If I visit the API directly (going to local-laravel-api in the browser) the cookies exist and I am authenticated.

So basically, it seems the proxy isn't picking up the cookies (and I have no idea why).

I've seen multiple threads on the net discussing the same issues, I've exhausted all those and still cannot access the API.

Does anyone have any ideas that could shed some light on this issue?

Any help is greatly appreciated!

jasonaburton
  • 2,941
  • 7
  • 34
  • 48
  • 1
    Is this only happening when developing locally? If you deploy your solution on the same domain do you still see the error? I have not tested this but I think you may be able to set the cookieDomainRewrite property in your proxy config file. See https://github.com/chimurai/http-proxy-middleware#http-proxy-options – JoAMoS Aug 14 '19 at 06:50
  • 1
    I just realized this is an almost 2 year old question but hopefully, if someone else ends up here this information might help – JoAMoS Aug 14 '19 at 06:53

1 Answers1

11

Try "cookieDomainRewrite": "localhost", as additional setting in proxy conf.

Alex Rempel
  • 480
  • 6
  • 12