fix: 本地开发支持 DB_DRIVER=sqlite 零依赖启动(test2 PG 不可达时后端启动即崩)

This commit is contained in:
Sisyphus committed 2026-08-25 23:12:41 +08:00
1 parent c05339e21c
commit 0deabfed45
2 files changed
+13 -2

No files matched your search

+9 -1
View File
@@ -82,7 +82,15 @@ export function createApp(db?: Db): Express {
const isMain = process.argv[1] !== undefined && process.argv[1]!.endsWith("server.ts");
if (isMain) {
void (async (): Promise<void> => {
await initDatabase();
// DB_DRIVER=sqlite → 本地零依赖文件库(data/perler-lab.db,可用 DB_PATH 覆盖路径)。
// 办公网连不上 test2 PostgreSQL(DEFAULT_DATABASE_URL 超时)时也能本地开发;
// 缺省仍走 PostgreSQL(DATABASE_URL / DEFAULT_DATABASE_URL),测试/生产不受影响。
if (process.env["DB_DRIVER"] === "sqlite") {
const dbPath = process.env["DB_PATH"];
initDatabase(dbPath === undefined ? {} : { dbPath });
} else {
await initDatabase();
}
createApp().listen(PORT, () => {
console.log(`PERLER LAB server running on http://localhost:${PORT}`);
});
+4 -1
View File
@@ -54,8 +54,11 @@ if not errorlevel 1 (
echo.
rem ---------- 3. Start backend (separate minimized window) ----------
rem DB_DRIVER=sqlite: local dev runs on a zero-dependency SQLite file DB.
rem The default PostgreSQL (test2, 172.16.0.11:54322) is unreachable from
rem office networks, which crashed the backend on startup (pg connect timeout).
echo [START] Starting backend service http://localhost:8788 ...
start "PERLER LAB Backend" /min cmd /c "cd /d ""%~dp0perler-lab-server"" && npx tsx src/server.ts"
start "PERLER LAB Backend" /min cmd /c "cd /d ""%~dp0perler-lab-server"" && set DB_DRIVER=sqlite&& npx tsx src/server.ts"
rem ---------- 4. Wait 3 seconds for the backend to boot ----------
rem ping is used instead of timeout because timeout fails when stdin is