Add env-driven SMTP and app identity settings for PocketBase
- 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
This commit is contained in:
@@ -12,6 +12,7 @@ RUN curl -fsSL "https://github.com/pocketbase/pocketbase/releases/download/v${PB
|
||||
&& rm pb.zip
|
||||
|
||||
COPY pb_migrations ./pb_migrations
|
||||
COPY pb_hooks ./pb_hooks
|
||||
COPY entrypoint.sh ./
|
||||
RUN chmod +x entrypoint.sh pocketbase
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* 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);
|
||||
});
|
||||
Reference in New Issue
Block a user