//打包取到的标识
const NODE_ENV = process.env.NODE_ENV;
//测试标识
const DEVELOPMENT_ENV = "development";
//正式标识
const PRODUCTION_ENV = "production";
enum Platform {
DEV = "DEV",
PROD = "PROD",
}
interface IPlatformType {
[keyName: string]: IPlatformItem;
}
interface IPlatformItem {
name: string;
readonly url: string;
readonly socketUrl: string;
}
const isPlatform: string =
NODE_ENV == DEVELOPMENT_ENV ? Platform.DEV : Platform.PROD;
const PlatformType: IPlatformType = {
[Platform.DEV]: {
name: Platform.DEV,
url: "http://127.0.0.1:8086/",
socketUrl: "ws://localhost:8086/",
},
[Platform.PROD]: {
name: Platform.PROD,
url: "https://**********/",
socketUrl: "wss://**********/",
},
};
export default PlatformType[isPlatform];
在项目出现这个报错主要是Platform.DEV下的url:"http://127.0.0.1:8086/"最后面的(/)漏掉了,导致合成的路径不完整,所以报错:无效的URL
报错:request:fail Failed to execute 'open' on 'XMLHttpRequest': Invalid URL