- 规避模拟器 localhost→::1 的 IPv6 解析歧义导致的 ERR_CONNECTION_REFUSED (onLaunch 全量启动拉取 /app/config 失败后不自动重试,热重载不重跑) - 生产 base 不变;仅 env.ts/env.js 的 isDev 分支
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
/**
|
|
* 环境配置
|
|
*/
|
|
declare const wx: WechatMiniprogram.Wx;
|
|
|
|
function isDev(): boolean {
|
|
try {
|
|
const accountInfo = typeof wx.getAccountInfoSync === 'function'
|
|
? wx.getAccountInfoSync()
|
|
: null;
|
|
if (accountInfo?.miniProgram?.envVersion === 'develop') {
|
|
return true;
|
|
}
|
|
|
|
const info = (wx.getDeviceInfo ? wx.getDeviceInfo() : wx.getSystemInfoSync()) as any;
|
|
return info.platform === 'devtools';
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// 生产环境后端地址(线上正式域名)。
|
|
// 部署前必须替换为真实域名,并到小程序后台「开发管理 → 开发设置 → 服务器域名」配置 request 合法域名。
|
|
// 如需在构建期注入(CI/打包脚本),可在打包前以全局 __DY_PROD_API_BASE__ 覆盖本默认值。
|
|
declare const __DY_PROD_API_BASE__: string | undefined;
|
|
const PROD_API_BASE_URL: string =
|
|
(typeof __DY_PROD_API_BASE__ !== 'undefined' ? __DY_PROD_API_BASE__ : undefined)
|
|
|| 'https://api.danyang-match.example.com/api/v1'; // TODO(部署): 替换为真实生产域名
|
|
|
|
export const API_BASE_URL: string = isDev()
|
|
? 'http://127.0.0.1:8085/api/v1'
|
|
: PROD_API_BASE_URL;
|
|
|
|
export const IS_DEV: boolean = isDev();
|