- pb_hooks/main.pb.js: bootstrap hook applying SMTP + meta settings from env vars on every boot (mail disabled when SMTP_HOST is unset) - docker-compose.yml: expose SMTP_* / PB_APP_URL on the pocketbase service - pocketbase/Dockerfile: bundle pb_hooks - README: document the new variables
37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
/**
|
|
* Apply app identity and SMTP settings from environment variables on every
|
|
* boot, so mail config stays declarative (docker-compose / Coolify env vars).
|
|
* These values win over the admin UI (Settings → Mail) — change them via env.
|
|
*/
|
|
onBootstrap((e) => {
|
|
e.next();
|
|
|
|
const settings = $app.settings();
|
|
|
|
// App identity, used in transactional emails (verification, reset, etc.)
|
|
settings.meta.appName = "PokeShare";
|
|
const appUrl = $os.getenv("PB_APP_URL");
|
|
if (appUrl) settings.meta.appUrl = appUrl;
|
|
|
|
const host = $os.getenv("SMTP_HOST");
|
|
if (!host) {
|
|
// No SMTP configured — save identity settings and keep mail disabled
|
|
$app.save(settings);
|
|
return;
|
|
}
|
|
|
|
const senderAddress = $os.getenv("SMTP_SENDER_ADDRESS");
|
|
const senderName = $os.getenv("SMTP_SENDER_NAME");
|
|
if (senderAddress) settings.meta.senderAddress = senderAddress;
|
|
if (senderName) settings.meta.senderName = senderName;
|
|
|
|
settings.smtp.enabled = true;
|
|
settings.smtp.host = host;
|
|
settings.smtp.port = parseInt($os.getenv("SMTP_PORT") || "587", 10);
|
|
settings.smtp.username = $os.getenv("SMTP_USERNAME") || "";
|
|
settings.smtp.password = $os.getenv("SMTP_PASSWORD") || "";
|
|
settings.smtp.tls = ($os.getenv("SMTP_TLS") || "true") === "true";
|
|
|
|
$app.save(settings);
|
|
});
|