更新: 删除 通过 .env 读入 ossurl 环境变量
This commit is contained in:
parent
ba2aff52ef
commit
b7b165c860
1
.gitignore
vendored
1
.gitignore
vendored
@ -17,6 +17,7 @@ _.log
|
|||||||
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
||||||
|
|
||||||
# dotenv environment variable files
|
# dotenv environment variable files
|
||||||
|
.env
|
||||||
.env.development.local
|
.env.development.local
|
||||||
.env.test.local
|
.env.test.local
|
||||||
.env.production.local
|
.env.production.local
|
||||||
|
|||||||
10
src/env.ts
10
src/env.ts
@ -1,6 +1,3 @@
|
|||||||
import dotenv from "dotenv";
|
|
||||||
import path from "node:path";
|
|
||||||
|
|
||||||
// 判断是否为打包后的 Electron 环境
|
// 判断是否为打包后的 Electron 环境
|
||||||
const isElectron = typeof process.versions?.electron !== "undefined";
|
const isElectron = typeof process.versions?.electron !== "undefined";
|
||||||
let isPackaged = false;
|
let isPackaged = false;
|
||||||
@ -9,13 +6,6 @@ if (isElectron) {
|
|||||||
isPackaged = app.isPackaged;
|
isPackaged = app.isPackaged;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 仅在非 Electron 环境加载 .env(例如 Docker / Web 后端)
|
|
||||||
if (!isElectron) {
|
|
||||||
dotenv.config({
|
|
||||||
path: path.resolve(process.cwd(), ".env"),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//加载环境变量(打包环境默认使用 prod)
|
//加载环境变量(打包环境默认使用 prod)
|
||||||
const env = process.env.NODE_ENV;
|
const env = process.env.NODE_ENV;
|
||||||
if (!env) {
|
if (!env) {
|
||||||
|
|||||||
@ -51,7 +51,7 @@ class OSS {
|
|||||||
const safePath = normalizeUserPath(userRelPath);
|
const safePath = normalizeUserPath(userRelPath);
|
||||||
// URL 始终使用 /,所以这里需要将系统分隔符转回 /
|
// URL 始终使用 /,所以这里需要将系统分隔符转回 /
|
||||||
let url = `/${prefix}/`;
|
let url = `/${prefix}/`;
|
||||||
if (!process.env.ossURL || process.env.ossURL != "") url = process.env.ossURL + `/${prefix}/`;
|
if (process.env.ossURL && process.env.ossURL !== "") url = process.env.ossURL + `/${prefix}/`;
|
||||||
if (process.env.NODE_ENV == "dev") url = `http://localhost:10588/${prefix}/`;
|
if (process.env.NODE_ENV == "dev") url = `http://localhost:10588/${prefix}/`;
|
||||||
if (isEletron()) url = `http://localhost:${process.env.PORT}/${prefix}/`;
|
if (isEletron()) url = `http://localhost:${process.env.PORT}/${prefix}/`;
|
||||||
return `${url}${safePath.split(path.sep).join("/")}`;
|
return `${url}${safePath.split(path.sep).join("/")}`;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user