This commit is contained in:
Vaica committed 2026-06-21 22:56:07 +08:00
1 parent 62dbbdcae3
commit d3365ab77a
2 files changed
+29 -8

No files matched your search

+5 -2
View File
@@ -8,5 +8,8 @@ mkdir -p /app/recycle/posts /app/recycle/meta /app/logs /app/backups
# 修复权限
chown -R nextjs:nodejs /app/recycle /app/logs /app/backups
# 以 nextjs 用户启动应用
exec su-exec nextjs "$@"
# 调试:打印环境变量
echo "[entrypoint] BLOG_ROOT=$BLOG_ROOT"
# 以 nextjs 用户启动应用(保留环境变量)
exec su-exec nextjs env "$@"
+24 -6
View File
@@ -1,12 +1,30 @@
import path from "path";
import fs from "fs";
import os from "os";
// 支持环境变量配置 BLOG_ROOT(Linux 部署)
// Docker 部署时,BLOG_ROOT 通过 Docker 环境变量传入,不要放在 .env 文件中
const envBlogRoot = process.env.BLOG_ROOT;
export const BLOG_ROOT = envBlogRoot && envBlogRoot.trim()
? path.resolve(envBlogRoot)
: path.resolve(process.cwd(), "..");
// 获取博客根目录
// 优先级:BLOG_ROOT 环境变量 > Docker 挂载 /blog > 上级目录
function getBlogRoot(): string {
// 1. 环境变量
const envRoot = process.env.BLOG_ROOT;
if (envRoot && envRoot.trim() && envRoot !== "undefined") {
const resolved = path.resolve(envRoot);
if (fs.existsSync(path.join(resolved, "content"))) {
return resolved;
}
}
// 2. Docker 挂载检测
const dockerPath = "/blog";
if (fs.existsSync(path.join(dockerPath, "content"))) {
return dockerPath;
}
// 3. 回退到上级目录
return path.resolve(process.cwd(), "..");
}
export const BLOG_ROOT = getBlogRoot();
export const CONTENT_DIR = path.join(BLOG_ROOT, "content", "posts");
export const STATIC_DIR = path.join(BLOG_ROOT, "static");