decentralised message store

feat: dotenv for env vars

serenity bc349b34 06774e59

Changed files
+34
src
lib
+1
package.json
···
},
"dependencies": {
"@libsql/client": "^0.15.15",
+
"dotenv": "^17.2.3",
"fastify": "^5.6.1"
}
}
+9
pnpm-lock.yaml
···
'@libsql/client':
specifier: ^0.15.15
version: 0.15.15
+
dotenv:
+
specifier: ^17.2.3
+
version: 17.2.3
fastify:
specifier: ^5.6.1
version: 5.6.1
···
dir-glob@3.0.1:
resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==}
engines: {node: '>=8'}
+
+
dotenv@17.2.3:
+
resolution: {integrity: sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==}
+
engines: {node: '>=12'}
escape-string-regexp@4.0.0:
resolution: {integrity: sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==}
···
dir-glob@3.0.1:
dependencies:
path-type: 4.0.0
+
+
dotenv@17.2.3: {}
escape-string-regexp@4.0.0: {}
+24
src/lib/env.ts
···
+
import "dotenv/config";
+
+
const dbUrl = process.env.DB_URL;
+
if (!dbUrl)
+
console.warn("Environment DB_URL not set. Defaulting to `:memory:`");
+
export const DB_URL = dbUrl ?? ":memory:";
+
+
const authToken = process.env.AUTH_TOKEN;
+
if (!authToken) {
+
if (DB_URL !== ":memory:" && !DB_URL.startsWith("file:")) {
+
console.warn(
+
`You have not set AUTH_TOKEN but are using a remote database at ${DB_URL}. Please ensure that this is correct.`,
+
);
+
} else {
+
console.log(`No AUTH_TOKEN set. DB_URL is set as ${DB_URL}`);
+
}
+
}
+
export const AUTH_TOKEN = authToken;
+
+
const encPassphrase = process.env.ENC_PASSPHRASE;
+
if (!encPassphrase)
+
console.warn("No PASSPHRASE set. Contents will NOT be encrypted at rest");
+
else console.log("PASSPHRASE is set. Contents will he encrypted at rest");
+
export const ENC_PASSPHRASE = encPassphrase;