Migrate env variables to Cloudron
This commit is contained in:
+20
-2
@@ -8,6 +8,24 @@ export function getSessionPepper(): string {
|
||||
return secret;
|
||||
}
|
||||
|
||||
export function isDatabaseConfigured(): boolean {
|
||||
return Boolean(process.env.DATABASE_URL?.trim());
|
||||
export function getDatabaseUrl(): string | undefined {
|
||||
return process.env.CLOUDRON_POSTGRESQL_URL?.trim() || undefined;
|
||||
}
|
||||
|
||||
export function getSmtpUrl(): string | undefined {
|
||||
const server = process.env.CLOUDRON_MAIL_SMTP_SERVER?.trim();
|
||||
const port = process.env.CLOUDRON_MAIL_SMTP_PORT?.trim();
|
||||
if (!server || !port) return undefined;
|
||||
|
||||
const username = process.env.CLOUDRON_MAIL_SMTP_USERNAME?.trim() ?? "";
|
||||
const password = process.env.CLOUDRON_MAIL_SMTP_PASSWORD?.trim() ?? "";
|
||||
if (username || password) {
|
||||
const auth = `${encodeURIComponent(username)}:${encodeURIComponent(password)}@`;
|
||||
return `smtp://${auth}${server}:${port}`;
|
||||
}
|
||||
return `smtp://${server}:${port}`;
|
||||
}
|
||||
|
||||
export function isDatabaseConfigured(): boolean {
|
||||
return Boolean(getDatabaseUrl());
|
||||
}
|
||||
|
||||
+9
-8
@@ -1,18 +1,19 @@
|
||||
import nodemailer from "nodemailer";
|
||||
import { logger } from "../logger";
|
||||
import { getSmtpUrl } from "./env";
|
||||
|
||||
export async function sendMagicLinkEmail(
|
||||
to: string,
|
||||
verifyUrl: string,
|
||||
): Promise<void> {
|
||||
const url = process.env.SMTP_URL;
|
||||
const url = getSmtpUrl();
|
||||
|
||||
if (!url) {
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
logger.info(`[dev] Magic link for ${to}: ${verifyUrl}`);
|
||||
return;
|
||||
}
|
||||
throw new Error("SMTP_URL is not configured");
|
||||
throw new Error("CLOUDRON_MAIL_SMTP_* is not configured");
|
||||
}
|
||||
|
||||
const transporter = nodemailer.createTransport(url);
|
||||
@@ -33,7 +34,7 @@ export async function sendRuleStakeholderInviteEmail(
|
||||
verifyUrl: string,
|
||||
ruleTitle: string,
|
||||
): Promise<void> {
|
||||
const url = process.env.SMTP_URL;
|
||||
const url = getSmtpUrl();
|
||||
|
||||
if (!url) {
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
@@ -42,7 +43,7 @@ export async function sendRuleStakeholderInviteEmail(
|
||||
);
|
||||
return;
|
||||
}
|
||||
throw new Error("SMTP_URL is not configured");
|
||||
throw new Error("CLOUDRON_MAIL_SMTP_* is not configured");
|
||||
}
|
||||
|
||||
const transporter = nodemailer.createTransport(url);
|
||||
@@ -66,7 +67,7 @@ export async function sendOrganizerInquiryNotification(params: {
|
||||
requestId: string;
|
||||
}): Promise<void> {
|
||||
const { to, fromEmail, visitorEmail, message, requestId } = params;
|
||||
const url = process.env.SMTP_URL;
|
||||
const url = getSmtpUrl();
|
||||
|
||||
if (!url) {
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
@@ -75,7 +76,7 @@ export async function sendOrganizerInquiryNotification(params: {
|
||||
);
|
||||
return;
|
||||
}
|
||||
throw new Error("SMTP_URL is not configured");
|
||||
throw new Error("CLOUDRON_MAIL_SMTP_* is not configured");
|
||||
}
|
||||
|
||||
const transporter = nodemailer.createTransport(url);
|
||||
@@ -93,14 +94,14 @@ export async function sendEmailChangeEmail(
|
||||
to: string,
|
||||
verifyUrl: string,
|
||||
): Promise<void> {
|
||||
const url = process.env.SMTP_URL;
|
||||
const url = getSmtpUrl();
|
||||
|
||||
if (!url) {
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
logger.info(`[dev] Email change verify for ${to}: ${verifyUrl}`);
|
||||
return;
|
||||
}
|
||||
throw new Error("SMTP_URL is not configured");
|
||||
throw new Error("CLOUDRON_MAIL_SMTP_* is not configured");
|
||||
}
|
||||
|
||||
const transporter = nodemailer.createTransport(url);
|
||||
|
||||
@@ -50,7 +50,7 @@ export function errorJson(
|
||||
export function dbUnavailable(): NextResponse {
|
||||
return errorJson(
|
||||
"db_unavailable",
|
||||
"Database is not configured (DATABASE_URL).",
|
||||
"Database is not configured (CLOUDRON_POSTGRESQL_URL).",
|
||||
503,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user