我有路径让路径= "/";
当它调用此路径时,Angular使路径类似:
http://localhost:4200/backend/api
但是我需要
http://localhost/backend/api
没有端口,如何在Angular中设置此选项?
const baseUrl = "http://localhost"
例如:
environment.ts文件:
export const environment = {
DefaultLanguage: "en",
production: false,
development: true,
environmentName:"DEV",
baseURL:"http://localhost:8080/api/" // your will be http://localhost/backend/api
};
environment.prod.ts:
export const environment = { DefaultLanguage: "en", production: true, development: false, environmentName:"PROD", ResultsPerPage:[5,10,25,50,75,100], baseURL:null };
然后您可以将一些逻辑应用为:
if (environment.development) { this.baseURL = environment.baseURL; } else { this.baseURL = (platformLocation as any).location.origin + "/api/"; }
您可以使用不同的URL硬编码或基于逻辑的URL创建多个环境。