44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
"use strict";
|
|
const common_env = require("./env.js");
|
|
const API_TARGETS = {
|
|
local: "http://localhost:8090/",
|
|
prod: "https://api.huayang-star.com/"
|
|
};
|
|
const ENV_ALIAS = {
|
|
development: "local",
|
|
production: "prod",
|
|
local: "local",
|
|
prod: "prod"
|
|
};
|
|
function normalizeBaseUrl(url) {
|
|
return url.endsWith("/") ? url : `${url}/`;
|
|
}
|
|
function resolveApiEnv() {
|
|
var _a;
|
|
const fileEnv = (_a = common_env.envConfig) == null ? void 0 : _a.apiEnv;
|
|
{
|
|
const mapped = ENV_ALIAS[fileEnv.toLowerCase()];
|
|
if (mapped) {
|
|
return mapped;
|
|
}
|
|
}
|
|
const runtimeEnv = typeof process !== "undefined" && (process == null ? void 0 : process.env) ? process.env.UNI_APP_API_ENV || "development" : "";
|
|
const aliasKey = runtimeEnv ? runtimeEnv.toLowerCase() : "";
|
|
const env = ENV_ALIAS[aliasKey] || "prod";
|
|
return env;
|
|
}
|
|
const API_ENV = resolveApiEnv();
|
|
const API_BASE_URL = normalizeBaseUrl(API_TARGETS[API_ENV] || API_TARGETS.prod);
|
|
function getApiEnv() {
|
|
return API_ENV;
|
|
}
|
|
function getApiUrl(path = "") {
|
|
const apiPath = path.startsWith("/") ? path : `/${path}`;
|
|
const fullPath = apiPath.startsWith("/") ? apiPath.slice(1) : apiPath;
|
|
const fullUrl = `${API_BASE_URL}${fullPath}`;
|
|
return fullUrl;
|
|
}
|
|
exports.getApiEnv = getApiEnv;
|
|
exports.getApiUrl = getApiUrl;
|
|
//# sourceMappingURL=../../.sourcemap/mp-weixin/common/config.js.map
|