import axios from 'axios' ; const replaceHostnames = { } ; export function registerHostnameReplacing ( fromHostname , toHostname ) { if ( Object . keys ( replaceHostnames ) . length === 0 ) { axios . interceptors . request . use ( replaceHostnamesInterceptor , error => Promise . reject ( error ) ) ; } replaceHostnames [ fromHostname ] = toHostname ; } const replaceHostnamesInterceptor = async ( config ) : Promise < any > => { const originalUrl = new URL ( config . url ) ; if ( replaceHostnames [ originalUrl . hostname ] === undefined ) { return config ; } originalUrl . hostname = replaceHostnames [ originalUrl . hostname ] ; config . url = originalUrl . toString ( ) ; return config ; } ;