Angular Universal SSR not reaching api with error 'ErrorEvent is not defined'

181 Views Asked by At

I'm working on an app using Angular 14 and Angular universal. On my server express, i have an endpoint called /api. I can use it from the client side without problem. If i call it on a browser directly, it will display the object. To do it, i have a service using httpclient.

return this.httpClient
  .get<Record<string, T>>(url, {
   headers: {'Content-Type': 'application/json' }
  });

I have a pipe after that one but it's not important here.

My url is : 'http://localhost:4000/api/endpoint'.

My problem is that when i start my app using ssr, the first loading (the one from ssr) it's not loading data, it return an error 'ErrorEvent is not defined'. It's an error that happen when my backend cant be reach. The problem is that if i use the same url on my browser it's working like a charm. During the second loading (Browser side) this time my data has been successfully retrieved.

I can't have more information about this error, when i used an interceptor, i just have a object with status: 0.

If i use npm run dev:ssr to build the app (create the dist) and then npm run serve:ssr it's working well. If i use ng build to build then npm run serve:ssr, the ssr part is not working .

Thank you in advance for your help

I've tried both absolute and relative paths, renderModule and PlatformConfig but nothing changed.

0

There are 0 best solutions below