diff --git a/.gitignore b/.gitignore index 39dbfbbb..941b4a78 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .env +.env.* *.cpuprofile *.swp deno-test.xml \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 08db0c2b..71bc9c63 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,7 +28,7 @@ test: - postgres:16 variables: DITTO_NSEC: nsec1zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs4rm7hz - TEST_DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres + DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres POSTGRES_HOST_AUTH_METHOD: trust artifacts: when: always diff --git a/deno.json b/deno.json index 57d90ab9..0de69b95 100644 --- a/deno.json +++ b/deno.json @@ -1,27 +1,27 @@ { "version": "1.1.0", "tasks": { - "start": "deno run -A src/server.ts", - "dev": "deno run -A --watch src/server.ts", + "start": "deno run -A --env-file src/server.ts", + "dev": "deno run -A --env-file --watch src/server.ts", "hook": "deno run --allow-read --allow-run --allow-write https://deno.land/x/deno_hooks@0.1.1/mod.ts", - "db:export": "deno run -A scripts/db-export.ts", - "db:import": "deno run -A scripts/db-import.ts", - "db:migrate": "deno run -A scripts/db-migrate.ts", - "nostr:pull": "deno run -A scripts/nostr-pull.ts", - "debug": "deno run -A --inspect src/server.ts", - "test": "deno test -A --junit-path=./deno-test.xml", + "db:export": "deno run -A --env-file scripts/db-export.ts", + "db:import": "deno run -A --env-file scripts/db-import.ts", + "db:migrate": "deno run -A --env-file scripts/db-migrate.ts", + "nostr:pull": "deno run -A --env-file scripts/nostr-pull.ts", + "debug": "deno run -A --env-file --inspect src/server.ts", + "test": "deno test -A --env-file=.env.test --junit-path=./deno-test.xml", "check": "deno check --allow-import src/server.ts", "nsec": "deno run scripts/nsec.ts", - "admin:event": "deno run -A scripts/admin-event.ts", - "admin:role": "deno run -A scripts/admin-role.ts", - "setup": "deno run -A scripts/setup.ts", - "setup:kind0": "deno run -A scripts/setup-kind0.ts", - "stats:recompute": "deno run -A scripts/stats-recompute.ts", + "admin:event": "deno run -A --env-file scripts/admin-event.ts", + "admin:role": "deno run -A --env-file scripts/admin-role.ts", + "setup": "deno run -A --env-file scripts/setup.ts", + "setup:kind0": "deno run -A --env-file scripts/setup-kind0.ts", + "stats:recompute": "deno run -A --env-file scripts/stats-recompute.ts", "soapbox": "curl -O https://dl.soapbox.pub/main/soapbox.zip && mkdir -p public && mv soapbox.zip public/ && cd public/ && unzip -o soapbox.zip && rm soapbox.zip", - "trends": "deno run -A scripts/trends.ts", + "trends": "deno run -A --env-file scripts/trends.ts", "clean:deps": "deno cache --reload src/app.ts", - "db:populate-search": "deno run -A scripts/db-populate-search.ts", - "vapid": "deno run -A scripts/vapid.ts" + "db:populate-search": "deno run -A --env-file scripts/db-populate-search.ts", + "vapid": "deno run scripts/vapid.ts" }, "unstable": [ "cron", @@ -54,7 +54,6 @@ "@std/assert": "jsr:@std/assert@^0.225.1", "@std/cli": "jsr:@std/cli@^0.223.0", "@std/crypto": "jsr:@std/crypto@^0.224.0", - "@std/dotenv": "jsr:@std/dotenv@^0.224.0", "@std/encoding": "jsr:@std/encoding@^0.224.0", "@std/fs": "jsr:@std/fs@^0.229.3", "@std/json": "jsr:@std/json@^0.223.0", diff --git a/deno.lock b/deno.lock index 24c4ed15..c0e4711c 100644 --- a/deno.lock +++ b/deno.lock @@ -59,7 +59,6 @@ "jsr:@std/bytes@^1.0.2-rc.3": "1.0.2", "jsr:@std/cli@0.223": "0.223.0", "jsr:@std/crypto@0.224": "0.224.0", - "jsr:@std/dotenv@0.224": "0.224.2", "jsr:@std/encoding@0.213.1": "0.213.1", "jsr:@std/encoding@0.224": "0.224.3", "jsr:@std/encoding@0.224.0": "0.224.0", @@ -527,9 +526,6 @@ "@std/dotenv@0.224.0": { "integrity": "d9234cdf551507dcda60abb6c474289843741d8c07ee8ce540c60f5c1b220a1d" }, - "@std/dotenv@0.224.2": { - "integrity": "29081695357e4534696c9e986b2560be29c141ccf52daa32b6c20ff5b5c64ab9" - }, "@std/encoding@0.213.1": { "integrity": "fcbb6928713dde941a18ca5db88ca1544d0755ec8fb20fe61e2dc8144b390c62" }, @@ -2101,7 +2097,6 @@ "jsr:@std/assert@~0.225.1", "jsr:@std/cli@0.223", "jsr:@std/crypto@0.224", - "jsr:@std/dotenv@0.224", "jsr:@std/encoding@0.224", "jsr:@std/fs@~0.229.3", "jsr:@std/json@0.223", diff --git a/scripts/trends.ts b/scripts/trends.ts index 627fb332..6600f7e2 100644 --- a/scripts/trends.ts +++ b/scripts/trends.ts @@ -1,5 +1,4 @@ import { z } from 'zod'; -import '@/config.ts'; import { updateTrendingEvents, diff --git a/src/config.ts b/src/config.ts index 530ecbb2..cd8e2a4c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,6 +1,5 @@ import os from 'node:os'; import ISO6391, { LanguageCode } from 'iso-639-1'; -import * as dotenv from '@std/dotenv'; import { getPublicKey, nip19 } from 'nostr-tools'; import { z } from 'zod'; import { decodeBase64 } from '@std/encoding/base64'; @@ -8,13 +7,6 @@ import { encodeBase64Url } from '@std/encoding/base64url'; import { getEcdsaPublicKey } from '@/utils/crypto.ts'; -/** Load environment config from `.env` */ -await dotenv.load({ - export: true, - defaultsPath: null, - examplePath: null, -}); - /** Application-wide configuration. */ class Conf { private static _pubkey: string | undefined; @@ -78,10 +70,6 @@ class Conf { static get databaseUrl(): string { return Deno.env.get('DATABASE_URL') ?? 'file://data/pgdata'; } - /** Database to use in tests. */ - static get testDatabaseUrl(): string { - return Deno.env.get('TEST_DATABASE_URL') ?? 'memory://'; - } /** PGlite debug level. 0 disables logging. */ static get pgliteDebug(): 0 | 1 | 2 | 3 | 4 | 5 { return Number(Deno.env.get('PGLITE_DEBUG') || 0) as 0 | 1 | 2 | 3 | 4 | 5; diff --git a/src/test.ts b/src/test.ts index 121b32cc..4e813f05 100644 --- a/src/test.ts +++ b/src/test.ts @@ -34,10 +34,9 @@ export function genEvent(t: Partial = {}, sk: Uint8Array = generateS return purifyEvent(event); } -/** Create a database for testing. It uses `TEST_DATABASE_URL`, or creates an in-memory database by default. */ +/** Create a database for testing. It uses `DATABASE_URL`, or creates an in-memory database by default. */ export async function createTestDB(opts?: { pure?: boolean }) { - const { testDatabaseUrl } = Conf; - const { kysely } = DittoDB.create(testDatabaseUrl, { poolSize: 1 }); + const { kysely } = DittoDB.create(Conf.databaseUrl, { poolSize: 1 }); await DittoDB.migrate(kysely);