#How can I use add an header to an Axios instnace just for one specific module ?

8 messages · Page 1 of 1 (latest)

analog dust
#

I'm importing the HttpModule in each module, and I'd like to add an headers as an Axios option just in one specific module.

Any ideas of how can i achieve it ?

sterile pond
#

If you're importing HttpModule.register in each module, then each module has its own copy of HttpService and axios. So you can just configure HttpModule differently in that particular module

analog dust
sterile pond
#

Interceptors inject providers from the module that they're used in. That means if you configure the HttpModule in one module diffferently, ypur interceptor will inject the HttpService from the module.

analog dust
#

ok, but how can I use the same http module (shared http module) with some common interceptors, and in one specific module to have the same interceptors but also have a specific header for all of its external requests ?
Instead of just add that header on each axios call.
Is it possible at all if configuring a http module (by forRoot or regsiter) creates a new axios instance ?

sterile pond
#

by interceptors do you mean Nest interceptors or Axios interceptorys?

sterile pond
# analog dust Axios interceptors

Ah, I see. Well, axios interceptors are bound to a specific instance of axios (and therefore HttpService). So what you can do is configure your common HttpModule in some wrapper module, re-export it, and import the wrapper module anywhere that the common functionaliy is needed. In modules where a different functionality is needed, configure a new HttpModule