;s
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
/**
|
||||
* 域名与根域配置 - 特色标识
|
||||
* 更换域名(如 *.hackrobot.cn -> *.nomadro.com)时,只需设置 ROOT_DOMAIN 或各独立变量
|
||||
*/
|
||||
|
||||
const isDev = process.env.NODE_ENV === "development";
|
||||
|
||||
export const ROOT_DOMAIN =
|
||||
process.env.ROOT_DOMAIN || process.env.NEXT_PUBLIC_ROOT_DOMAIN || "hackrobot.cn";
|
||||
|
||||
/** 支付 API 默认地址。生产环境固定为 api 域名,避免 .env 中 127.0.0.1 导致支付失败 */
|
||||
export const DEFAULT_PAYMENT_API_URL = isDev
|
||||
? "http://127.0.0.1:8007"
|
||||
: `https://api.${ROOT_DOMAIN}`;
|
||||
|
||||
/** 生产环境若 PAYMENT_API_URL 指向 localhost,则忽略并使用 api 域名 */
|
||||
export function resolvePaymentApiUrl(): string {
|
||||
const url = process.env.PAYMENT_API_URL || DEFAULT_PAYMENT_API_URL;
|
||||
if (!isDev && /^(https?:\/\/)?(127\.0\.0\.1|localhost)(:\d+)?(\/|$)/i.test(url)) {
|
||||
return `https://api.${ROOT_DOMAIN}`;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
export const DEFAULT_POCKETBASE_URL = `https://pocketbase.${ROOT_DOMAIN}`;
|
||||
|
||||
export const DEFAULT_MINIO_HOST = `minioweb.${ROOT_DOMAIN}`;
|
||||
|
||||
/** digital 专题站默认地址(用于跨站链接) */
|
||||
export const DEFAULT_DIGITAL_URL = `https://digital.${ROOT_DOMAIN}`;
|
||||
@@ -4,14 +4,10 @@ export { getHomeConfig, HOME_CONFIG, MEMBER_PHOTOS, TRAVELING_NOW, MEETUPS, HOT_
|
||||
export { FILTER_OPTIONS, FILTER_LABELS, type FilterOption } from "./filter.config";
|
||||
export { FOOTER_SECTIONS, getFooterSections, type FooterLink, type FooterSection } from "./footer.config";
|
||||
export {
|
||||
getPocketBaseConfig,
|
||||
getPaymentConfig,
|
||||
getJoinPaymentConfig,
|
||||
getMinioConfig,
|
||||
SITE_ID,
|
||||
} from "./services.config";
|
||||
export type {
|
||||
PocketBaseConfig,
|
||||
PaymentConfig,
|
||||
MinioConfig,
|
||||
} from "./services.config";
|
||||
|
||||
@@ -1,80 +1,23 @@
|
||||
/**
|
||||
* 服务配置 - PocketBase、支付、MinIO
|
||||
* 域名更换:设置 ROOT_DOMAIN(如 nomadro.com)可推导默认 API 地址
|
||||
* 前端服务配置。
|
||||
* 浏览器侧只保留 UI 需要的公开配置;后端地址、支付网关、存储和 PB 连接都由 FastAPI 持有。
|
||||
*/
|
||||
|
||||
import {
|
||||
DEFAULT_PAYMENT_API_URL,
|
||||
DEFAULT_POCKETBASE_URL,
|
||||
DEFAULT_MINIO_HOST,
|
||||
resolvePaymentApiUrl,
|
||||
} from "./domain.config";
|
||||
|
||||
export interface PocketBaseConfig {
|
||||
enabled: boolean;
|
||||
url: string;
|
||||
usersCollection: string;
|
||||
joinCollection: string;
|
||||
}
|
||||
|
||||
export interface PaymentConfig {
|
||||
enabled: boolean;
|
||||
apiUrl: string;
|
||||
provider: "zpay" | "xorpay";
|
||||
defaultAmount: number;
|
||||
defaultType: string;
|
||||
zpaySubmitUrl: string;
|
||||
}
|
||||
|
||||
export interface MinioConfig {
|
||||
enabled: boolean;
|
||||
endPoint: string;
|
||||
port: number;
|
||||
useSSL: boolean;
|
||||
bucket: string;
|
||||
accessKey: string;
|
||||
secretKey: string;
|
||||
region: string;
|
||||
publicUrl: string;
|
||||
uploadPrefix: string;
|
||||
}
|
||||
|
||||
const isDev = process.env.NODE_ENV === "development";
|
||||
const PAYJSAPI_PORT = process.env.PAYJSAPI_PORT || "8007";
|
||||
|
||||
/** 站点标识,用于 VIP 按站点隔离 */
|
||||
export const SITE_ID = process.env.NEXT_PUBLIC_SITE_ID || "meetup";
|
||||
|
||||
/** meetup 加入游牧中国 价格(分),88元=8800 */
|
||||
/** meetup 加入游牧中国价格(分),88 元 = 8800 */
|
||||
export const MEETUP_JOIN_AMOUNT = 8800;
|
||||
|
||||
export function getApiUrlFromRequest(hostHeader: string | null): string | null {
|
||||
if (!hostHeader) return null;
|
||||
if (!isDev) return resolvePaymentApiUrl();
|
||||
const hostname = hostHeader.split(":")[0];
|
||||
return `http://${hostname}:${PAYJSAPI_PORT}`;
|
||||
}
|
||||
|
||||
export function getPocketBaseConfig(): PocketBaseConfig {
|
||||
return {
|
||||
enabled: true,
|
||||
url:
|
||||
process.env.NEXT_PUBLIC_POCKETBASE_URL ||
|
||||
process.env.POCKETBASE_URL ||
|
||||
DEFAULT_POCKETBASE_URL,
|
||||
usersCollection: "users",
|
||||
joinCollection: process.env.POCKETBASE_JOIN_COLLECTION || "solan",
|
||||
};
|
||||
}
|
||||
|
||||
export function getPaymentConfig(): PaymentConfig {
|
||||
return {
|
||||
enabled: true,
|
||||
apiUrl: resolvePaymentApiUrl(),
|
||||
provider: (process.env.PAYMENT_PROVIDER as "zpay" | "xorpay") || "zpay",
|
||||
defaultAmount: Number(process.env.PAYMENT_DEFAULT_AMOUNT) || 8800,
|
||||
defaultType: process.env.PAYMENT_DEFAULT_TYPE || "meetup",
|
||||
zpaySubmitUrl: process.env.ZPAY_SUBMIT_URL || "https://zpayz.cn/submit.php",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -85,29 +28,3 @@ export function getJoinPaymentConfig(): { amount: number; type: string } {
|
||||
type: process.env.PAYMENT_JOIN_TYPE || "meetup",
|
||||
};
|
||||
}
|
||||
|
||||
export function getMinioConfig(themeOverride?: {
|
||||
bucket?: string;
|
||||
uploadPrefix?: string;
|
||||
}): MinioConfig {
|
||||
const endPoint = process.env.MINIO_ENDPOINT || DEFAULT_MINIO_HOST;
|
||||
const port = parseInt(process.env.MINIO_PORT || "9035", 10);
|
||||
const bucket = themeOverride?.bucket || process.env.MINIO_BUCKET || "hackrobot";
|
||||
const publicUrl =
|
||||
process.env.MINIO_PUBLIC_URL || `https://${endPoint}/${bucket}`;
|
||||
const uploadPrefix =
|
||||
themeOverride?.uploadPrefix || process.env.MINIO_UPLOAD_PREFIX || "joins";
|
||||
|
||||
return {
|
||||
enabled: true,
|
||||
endPoint,
|
||||
port,
|
||||
useSSL: process.env.MINIO_USE_SSL === "true",
|
||||
bucket,
|
||||
accessKey: process.env.MINIO_ACCESS_KEY || "",
|
||||
secretKey: process.env.MINIO_SECRET_KEY || "",
|
||||
region: process.env.MINIO_REGION || "china",
|
||||
publicUrl: publicUrl.replace(/\/$/, ""),
|
||||
uploadPrefix,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user