Cloudron-native environment variables #55
Reference in New Issue
Block a user
Delete Branch "adilallo/Backend/BridgeCloudronEnv"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Overview
Implements CR-96 by making Cloudron-injected env vars the sole source of truth for Postgres and SMTP. Drops
DATABASE_URLandSMTP_URLfrom the codebase so staging/production can run with only what Cloudron provides (CLOUDRON_POSTGRESQL_URL,CLOUDRON_MAIL_SMTP_*) plus manually configured vars (SESSION_SECRET,SMTP_FROM, etc.).Local dev uses the same variable names in
.env— only the names change, not the values. Unset mail vars in development still log magic-link URLs to the server console.Changes
lib/server/env.ts— addgetDatabaseUrl()andgetSmtpUrl()(assembles Nodemailer transport URL from four Cloudron mail vars);isDatabaseConfigured()readsCLOUDRON_POSTGRESQL_URLlib/server/mail.ts— all four send paths usegetSmtpUrl()instead ofSMTP_URLlib/server/responses.ts—dbUnavailable()message referencesCLOUDRON_POSTGRESQL_URLprisma/schema.prisma— datasource URL env name changed toCLOUDRON_POSTGRESQL_URL.env.example,scripts/migrate-smoke-local.sh,Dockerfilecomment — updated for Cloudron var namestests/unit/env.test.ts— unit tests for DB URL resolution, SMTP URL assembly (including credential encoding), and unset casesHow to Test
.env:DATABASE_URL→CLOUDRON_POSTGRESQL_URLCLOUDRON_MAIL_SMTP_SERVER=localhost,CLOUDRON_MAIL_SMTP_PORT=1025docker compose up -d postgres mailhognpx prisma migrate dev(ornpm run migrate:smokefor ephemeral DB smoke)npm run devGET /api/healthreturns{"ok":true,"database":"connected"}/logindelivers email to Mailhog (http://localhost:8025) or logs verify URL when mail vars are unset