2

I have upgraded Angular 5 to 7 and kept rxjs-compat. Application was working fine in this case, but later we removed rxjs-compat and done respective changes. And we are getting error while loading the application as "Enpoint unreachable" while bootstrapping the application. We are using

"@ngx-config/core": "7.0.0",
"@ngx-config/http-loader": "7.0.0",

I suspect this package is creating some issue after upgrade.But compilation is success, only while running the application it shows console error as endpoint unreachable. Any body else faced this issues or any idea how to debugg these kind of issues.

Any help will be appreciated

EDIT

After further analysis I found that, this error is happened because of @ngx-config update, nothing to do with rxjs-compat.

// for config loader
export function configFactory(http: HttpClient): ConfigLoader {
  return new ConfigHttpLoader(http, environment.configFile);
} 

Interceptor

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { 
//etc
})
Prashobh
  • 9,216
  • 15
  • 61
  • 91
  • 1
    Can you please post the entire exception / stack trace? – Julien Ambos Jan 24 '19 at 14:14
  • 1
    Can you share the entire error, and some more of your code. I actually had similar problem, if you just share a link to your repo, I'll try and fix it. – Alicia Sykes Jan 24 '19 at 14:23
  • @Lissy Http interceptor and config core are conflicting some how. If I remove http interceptor other one is working fine, either of one is working fine. Same thing is working fine in another application. – Prashobh Jan 28 '19 at 08:58
  • I tried this as well :- https://stackoverflow.com/questions/52910312/angular-6-use-http-interceptor-with-config-service but nothing seems to be worked so far. – Prashobh Jan 28 '19 at 09:03

1 Answers1

1

I tried many approaches mentioned in github and SO, nothing workout for me. Final thing which I done to make it work is,

Calling config in main .ts before application bootstraps and set in session storage, you can create a class file and do your logic there as well.

const url = "configurl"// read from your environment file
const xmlHttp = new XMLHttpRequest();
      xmlHttp.onreadystatechange = () => {
        if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
          if (xmlHttp.responseText) {
            const config: any = JSON.parse(xmlHttp.responseText);
            if (config) {
             window.sessionStorage.setItem("config", JSON.stringify(config));

            }
        }
      };
      xmlHttp.open("GET", url, true);
      xmlHttp.send(null); 

Appmodule

export function configFactory(http: HttpClient): ConfigLoader {
  return new ConfigStaticLoader(JSON.parse(window.sessionStorage.getItem("config")));
} 

And this works fine for me.

Original issue was , I am not able to use config loader and http interceptor together.

Prashobh
  • 9,216
  • 15
  • 61
  • 91