| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import { readFileSync } from "node:fs";
- import { fileURLToPath } from "node:url";
- import { defineConfig } from "@rsbuild/core";
- import { pluginReact } from "@rsbuild/plugin-react";
- import { pluginTailwindcss } from "@rsbuild/plugin-tailwindcss";
- const isDevelopment = process.env.NODE_ENV === "development";
- const DEV_PORT = Number(process.env.OSS_DEV_PORT ?? 5180);
- const DEV_PROXY_PATH = "/api-gateway";
- const gatewayTarget = process.env.OSS_GATEWAY_BASE;
- const apiBase = process.env.ENV_KLT_API_BASE_URL;
- /**
- * 项目空间(`end_user` 档)登录上下文:`auth/password@v1` 除 `scope_type/scope_id` 外
- * 还须带 `project_id/tenant_id/env/stage`,缺一即 11103;且 `challenge/verify@v1` 必须带
- * **同一份**上下文,否则 12006「challenge_token 与登录上下文不匹配」。
- *
- * 本地开发时,未配置的标识可从建号台账 temp/seoh_provision.json 读取。
- * ⚠️ 该台账同时含 `auth_key`/`auth_code` 两枚凭证,这里按字段白名单只读 tenant_id/
- * project_id,⛔ 整体读入或内联进产物。可用 OSS_SEOH_* 覆盖。
- */
- function seoCtx() {
- let j: { tenant_id?: string; project_id?: string } = {};
- if (isDevelopment) {
- try {
- j = JSON.parse(readFileSync(fileURLToPath(new URL("../temp/seoh_provision.json", import.meta.url)), "utf-8"));
- } catch {
- /* 台账缺失时留空,由登录页给出提示。 */
- }
- }
- return {
- tenant_id: process.env.OSS_SEOH_TENANT_ID ?? String(j.tenant_id ?? ""),
- project_id: process.env.OSS_SEOH_PROJECT_ID ?? String(j.project_id ?? ""),
- env: process.env.OSS_SEOH_ENV ?? (isDevelopment ? "nonprod" : "prod"),
- stage: process.env.OSS_SEOH_STAGE ?? (isDevelopment ? "dev" : "prod"),
- };
- }
- export default defineConfig({
- plugins: [pluginReact(), pluginTailwindcss()],
- source: {
- entry: {
- index: "./src/main.tsx",
- },
- define: {
- __SEO_CTX__: JSON.stringify(seoCtx()),
- "import.meta.env.ENV_KLT_API_BASE_URL": JSON.stringify(apiBase ?? ""),
- },
- },
- server: {
- port: DEV_PORT,
- ...(isDevelopment && gatewayTarget && apiBase === DEV_PROXY_PATH
- ? {
- host: "127.0.0.1",
- proxy: {
- [DEV_PROXY_PATH]: {
- target: gatewayTarget,
- changeOrigin: true,
- // 仅本地代理到开发网关的 HTTPS 请求跳过证书校验。
- secure: false,
- pathRewrite: { "^/api-gateway": "" },
- },
- },
- }
- : {}),
- },
- });
|