Cloudron-native environment variables #55

Merged
an.di merged 4 commits from adilallo/Backend/BridgeCloudronEnv into main 2026-05-23 20:46:21 +00:00
Owner

Overview

Implements CR-96 by making Cloudron-injected env vars the sole source of truth for Postgres and SMTP. Drops DATABASE_URL and SMTP_URL from 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 — add getDatabaseUrl() and getSmtpUrl() (assembles Nodemailer transport URL from four Cloudron mail vars); isDatabaseConfigured() reads CLOUDRON_POSTGRESQL_URL
  • lib/server/mail.ts — all four send paths use getSmtpUrl() instead of SMTP_URL
  • lib/server/responses.tsdbUnavailable() message references CLOUDRON_POSTGRESQL_URL
  • prisma/schema.prisma — datasource URL env name changed to CLOUDRON_POSTGRESQL_URL
  • .env.example, scripts/migrate-smoke-local.sh, Dockerfile comment — updated for Cloudron var names
  • Docs — CONTRIBUTING, testing-guide, ops-backend-deploy, backend-roadmap, backend-linear-tickets, template-recommendation-matrix, api-routes.mdc
  • tests/unit/env.test.ts — unit tests for DB URL resolution, SMTP URL assembly (including credential encoding), and unset cases

How to Test

  1. Update local .env:
    • Rename DATABASE_URLCLOUDRON_POSTGRESQL_URL
    • For Mailhog: CLOUDRON_MAIL_SMTP_SERVER=localhost, CLOUDRON_MAIL_SMTP_PORT=1025
  2. docker compose up -d postgres mailhog
  3. npx prisma migrate dev (or npm run migrate:smoke for ephemeral DB smoke)
  4. npm run dev
  5. Verify:
    • GET /api/health returns {"ok":true,"database":"connected"}
    • Magic-link request at /login delivers email to Mailhog (http://localhost:8025) or logs verify URL when mail vars are unset
  6. Automated checks:
    npx tsc --noEmit
    npx vitest run tests/unit/env.test.ts
    npm run migrate:smoke
    
## Overview Implements **CR-96** by making Cloudron-injected env vars the sole source of truth for Postgres and SMTP. Drops `DATABASE_URL` and `SMTP_URL` from 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`** — add `getDatabaseUrl()` and `getSmtpUrl()` (assembles Nodemailer transport URL from four Cloudron mail vars); `isDatabaseConfigured()` reads `CLOUDRON_POSTGRESQL_URL` - **`lib/server/mail.ts`** — all four send paths use `getSmtpUrl()` instead of `SMTP_URL` - **`lib/server/responses.ts`** — `dbUnavailable()` message references `CLOUDRON_POSTGRESQL_URL` - **`prisma/schema.prisma`** — datasource URL env name changed to `CLOUDRON_POSTGRESQL_URL` - **`.env.example`**, **`scripts/migrate-smoke-local.sh`**, **`Dockerfile`** comment — updated for Cloudron var names - **Docs** — CONTRIBUTING, testing-guide, ops-backend-deploy, backend-roadmap, backend-linear-tickets, template-recommendation-matrix, api-routes.mdc - **`tests/unit/env.test.ts`** — unit tests for DB URL resolution, SMTP URL assembly (including credential encoding), and unset cases ## How to Test 1. Update local `.env`: - Rename `DATABASE_URL` → `CLOUDRON_POSTGRESQL_URL` - For Mailhog: `CLOUDRON_MAIL_SMTP_SERVER=localhost`, `CLOUDRON_MAIL_SMTP_PORT=1025` 2. `docker compose up -d postgres mailhog` 3. `npx prisma migrate dev` (or `npm run migrate:smoke` for ephemeral DB smoke) 4. `npm run dev` 5. Verify: - `GET /api/health` returns `{"ok":true,"database":"connected"}` - Magic-link request at `/login` delivers email to Mailhog (`http://localhost:8025`) or logs verify URL when mail vars are unset 6. Automated checks: ```bash npx tsc --noEmit npx vitest run tests/unit/env.test.ts npm run migrate:smoke ```
an.di added 1 commit 2026-05-23 16:54:25 +00:00
an.di self-assigned this 2026-05-23 16:54:47 +00:00
an.di added 1 commit 2026-05-23 16:57:02 +00:00
an.di added 2 commits 2026-05-23 20:46:04 +00:00
an.di merged commit a14cae744d into main 2026-05-23 20:46:21 +00:00
an.di deleted branch adilallo/Backend/BridgeCloudronEnv 2026-05-23 20:46:21 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: CommunityRule/community-rule#55