Merge pull request #834 from mvanhorn/fix/dotenv-cwd-fallback
fix(server): load .env from cwd as fallback
This commit is contained in:
commit
bfaa4b4bdc
1 changed files with 10 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { readConfigFile } from "./config-file.js";
|
import { readConfigFile } from "./config-file.js";
|
||||||
import { existsSync } from "node:fs";
|
import { existsSync, realpathSync } from "node:fs";
|
||||||
|
import { resolve } from "node:path";
|
||||||
import { config as loadDotenv } from "dotenv";
|
import { config as loadDotenv } from "dotenv";
|
||||||
import { resolvePaperclipEnvPath } from "./paths.js";
|
import { resolvePaperclipEnvPath } from "./paths.js";
|
||||||
import {
|
import {
|
||||||
|
|
@ -27,6 +28,14 @@ if (existsSync(PAPERCLIP_ENV_FILE_PATH)) {
|
||||||
loadDotenv({ path: PAPERCLIP_ENV_FILE_PATH, override: false, quiet: true });
|
loadDotenv({ path: PAPERCLIP_ENV_FILE_PATH, override: false, quiet: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CWD_ENV_PATH = resolve(process.cwd(), ".env");
|
||||||
|
const isSameFile = existsSync(CWD_ENV_PATH) && existsSync(PAPERCLIP_ENV_FILE_PATH)
|
||||||
|
? realpathSync(CWD_ENV_PATH) === realpathSync(PAPERCLIP_ENV_FILE_PATH)
|
||||||
|
: CWD_ENV_PATH === PAPERCLIP_ENV_FILE_PATH;
|
||||||
|
if (!isSameFile && existsSync(CWD_ENV_PATH)) {
|
||||||
|
loadDotenv({ path: CWD_ENV_PATH, override: false, quiet: true });
|
||||||
|
}
|
||||||
|
|
||||||
type DatabaseMode = "embedded-postgres" | "postgres";
|
type DatabaseMode = "embedded-postgres" | "postgres";
|
||||||
|
|
||||||
export interface Config {
|
export interface Config {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue