plc: run dotenv before any other imports

This fixes, eg, logging configuration via .env variables.
This commit is contained in:
bryan newbold 2023-02-08 23:18:18 -08:00
parent 8b803e013c
commit 7b5f8906d1
2 changed files with 10 additions and 8 deletions
packages/plc/src

@ -1,15 +1,8 @@
import dotenv from 'dotenv'
import './env'
import { Database } from './server/db'
import PlcServer from './server'
const run = async () => {
const env = process.env.ENV
if (env) {
dotenv.config({ path: `./.${env}.env` })
} else {
dotenv.config()
}
const dbLoc = process.env.DATABASE_LOC
const dbPostgresUrl = process.env.DB_POSTGRES_URL

9
packages/plc/src/env.ts Normal file

@ -0,0 +1,9 @@
// NOTE: this file should be imported first, particularly before `@atproto/common` (for logging), to ensure that environment variables are respected in library code
import dotenv from 'dotenv'
const env = process.env.ENV
if (env) {
dotenv.config({ path: `./.${env}.env` })
} else {
dotenv.config()
}