0

Using spring boot and using scoped session:

@Service
@Scope(value="session", proxyMode = ScopedProxyMode.TARGET_CLASS)

I have setters and getters on this class and when the web service is run via 8081 the rest apis are scoped correctly in that the session is maintained and the data is cached.

However when I run the front end angular using ng serve via a proxy to the rest api, I noticed that the session is never maintained. ie the fields that have been initialized seems to be always reset back to null on subsequent calls from the ng serve.

the proxy config is:

{
  "/": {
    "target": "http://localhost:8081/app",
    "secure": false,
    "changeOrigin": true,
    "logLevel": "debug"
  }
}

and running it via:

ng serve --port 4201 --proxy-config proxy.conf.json

Also the http requests I am using is this: this.options = { withCredentials: true, headers: new HttpHeaders({ 'Content-Type': 'application/json', 'Access-Control-Allow-Credentials': 'true', 'Access-Control-Allow-Origin': '*', 'Cache-Control': 'no-cache' }) };

Subarb
  • 1
  • 2
  • Make sure that the cookies get sent as well, if not there is no session. – M. Deinum Nov 01 '22 at 12:35
  • @M.Deinum I have debugged a little more and noticed that the cookies are indeed not set. Something is going on when I use ng serve which doesn't set the cookies – Subarb Nov 01 '22 at 21:17
  • Maybe this helps: https://stackoverflow.com/questions/47045716/angular-ng-serve-with-proxy-config-doesnt-set-cookies-from-laravel-api – Jakob Em Nov 11 '22 at 15:47

0 Answers0