I have an angular 4 app and I am trying to find a best practices approach to creating a solution for creating a service or some sort of a solution for handling many urls for making http requests in a development as well as a production environment.
My solution at this point looks like this.
import { Injectable } from '@angular/core';
/**
* PathsService is like a properties file for all of the URL paths used in the application.
*/
@Injectable()
export class PathsService {
constructor() {}
productionEnvironment:string = "https://myproductionenvironment.com"
developmentEnvironment:string = "https://mydevelopmentenvironment.com"
activeRoot:string = productionEnvironment;
loginResource = "/loginresources"
employeeResource = "/employeeresouces"
public getLoginResources(): string {
return this.activeRoot+this.loginResource;
}
public getEmployeeResource():string {
return this.activeRoot+this.employeeResource;
}
}
While I believe this would work fine, there is a small problem because I have to change the activeRoot when switching from development to production environments. I am wondering if there is a better way to do this, so I don't have to manually switch. I could use javascript to take the url, parse it, and switch between production and development environments in that way, but it seems like there should be a better more angular way to solve this issue. Any input on this issue would be greatly appreciated. Thanks!