This commit is contained in:
eric
2026-03-10 04:41:20 -05:00
parent 82e79110fc
commit 0093294472
31 changed files with 5541 additions and 73 deletions

76
config/services.config.ts Normal file
View File

@@ -0,0 +1,76 @@
/**
* 服务配置 - 参考 desktop digital 项目
* PocketBase、支付(ZPAY)、MinIO 可通过环境变量覆盖
*/
const isDev = process.env.NODE_ENV === "development";
export interface PocketBaseConfig {
url: string;
}
export interface PaymentConfig {
apiUrl: string;
provider: "zpay" | "xorpay";
zpaySubmitUrl: string;
/** nomadvip 专用接口路径(固定 ZPAY,不影响 digital/cnomadcna) */
nomadvipPayPath: string;
}
export interface MinioConfig {
endPoint: string;
port: number;
useSSL: boolean;
bucket: string;
publicUrl: string;
}
export function getPocketBaseConfig(): PocketBaseConfig {
return {
url:
process.env.NEXT_PUBLIC_POCKETBASE_URL ||
process.env.POCKETBASE_URL ||
"https://pocketbase.hackrobot.cn",
};
}
/**
* 根据请求 Host 推断 payjsapi 地址(同主机:8700)
* 访问 192.168.41.222:3000 时自动用 192.168.41.222:8700,无需在 .env 写死 IP
*/
export function getApiUrlFromRequest(hostHeader: string | null): string {
if (!hostHeader) return isDev ? "http://127.0.0.1:8700" : "https://api.hackrobot.cn";
const hostname = hostHeader.split(":")[0];
return isDev ? `http://${hostname}:8700` : "https://api.hackrobot.cn";
}
export function getPaymentConfig(): PaymentConfig {
const apiUrl =
process.env.PAYMENT_API_URL ||
process.env.NEXT_PUBLIC_API_URL ||
(isDev ? "http://127.0.0.1:8700" : "https://api.hackrobot.cn");
return {
apiUrl,
provider: (process.env.PAYMENT_PROVIDER as "zpay" | "xorpay") || "zpay",
zpaySubmitUrl:
process.env.ZPAY_SUBMIT_URL || "https://zpayz.cn/submit.php",
nomadvipPayPath: "/nomadvip/payh5",
};
}
export function getMinioConfig(): MinioConfig {
const endPoint = process.env.MINIO_ENDPOINT || "minioweb.hackrobot.cn";
const port = parseInt(process.env.MINIO_PORT || "9035", 10);
const useSSL = process.env.MINIO_USE_SSL === "true";
const bucket = process.env.MINIO_BUCKET || "hackrobot";
const publicUrl =
process.env.MINIO_PUBLIC_URL || `https://${endPoint}/${bucket}`;
return {
endPoint,
port,
useSSL,
bucket,
publicUrl: publicUrl.replace(/\/$/, ""),
};
}