Files
danyang-match/miniapp/env.ts
T

35 lines
1.2 KiB
TypeScript
Raw Permalink Normal View History

2026-09-09 22:05:00 +08:00
/**
* 环境配置
*/
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;
}
2026-09-09 22:05:00 +08:00
const info = (wx.getDeviceInfo ? wx.getDeviceInfo() : wx.getSystemInfoSync()) as any;
return info.platform === 'devtools';
} catch {
return false;
}
}
2026-09-30 12:10:00 +08:00
// 生产环境后端地址(线上正式域名)。
// 部署前必须替换为真实域名,并到小程序后台「开发管理 → 开发设置 → 服务器域名」配置 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(部署): 替换为真实生产域名
2026-09-09 22:05:00 +08:00
export const API_BASE_URL: string = isDev()
? 'http://127.0.0.1:8085/api/v1'
2026-09-30 12:10:00 +08:00
: PROD_API_BASE_URL;
2026-09-09 22:05:00 +08:00
export const IS_DEV: boolean = isDev();