init
This commit is contained in:
42
backend/scripts/test-smtp.mjs
Normal file
42
backend/scripts/test-smtp.mjs
Normal file
@@ -0,0 +1,42 @@
|
||||
import { env } from "../src/config/env.ts";
|
||||
import { isMailConfigured, sendMail, verifyMailTransport } from "../src/lib/mail.ts";
|
||||
|
||||
const to = process.argv[2]?.trim();
|
||||
|
||||
if (!to) {
|
||||
console.error("Usage: npm run smtp:test -- <recipient@example.com>");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!isMailConfigured()) {
|
||||
console.error("SMTP is not configured.");
|
||||
console.error({
|
||||
host: env.SMTP_HOST,
|
||||
port: env.SMTP_PORT,
|
||||
secure: env.SMTP_SECURE,
|
||||
user: env.SMTP_USER,
|
||||
from: env.SMTP_FROM_EMAIL
|
||||
});
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log("Verifying SMTP transport...", {
|
||||
host: env.SMTP_HOST,
|
||||
port: env.SMTP_PORT,
|
||||
secure: env.SMTP_SECURE,
|
||||
user: env.SMTP_USER,
|
||||
from: env.SMTP_FROM_EMAIL,
|
||||
to
|
||||
});
|
||||
|
||||
await verifyMailTransport();
|
||||
console.log("SMTP transport verified.");
|
||||
|
||||
await sendMail({
|
||||
to,
|
||||
subject: "Alpinbet SMTP test",
|
||||
text: "This is a test email from the Alpinbet backend.",
|
||||
html: "<p>This is a test email from the Alpinbet backend.</p>"
|
||||
});
|
||||
|
||||
console.log("SMTP test email sent.");
|
||||
51
backend/scripts/with-db-url.mjs
Normal file
51
backend/scripts/with-db-url.mjs
Normal file
@@ -0,0 +1,51 @@
|
||||
import { spawn } from "node:child_process";
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
if (args.length === 0) {
|
||||
console.error("Usage: node scripts/with-db-url.mjs <command> [...args]");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const buildDatabaseUrl = () => {
|
||||
const host = process.env.POSTGRES_HOST?.trim() || "localhost";
|
||||
const port = process.env.POSTGRES_PORT?.trim() || "5432";
|
||||
const database = process.env.POSTGRES_DB?.trim();
|
||||
const user = process.env.POSTGRES_USER?.trim();
|
||||
const password = process.env.POSTGRES_PASSWORD ?? "";
|
||||
const schema = process.env.POSTGRES_SCHEMA?.trim() || "public";
|
||||
|
||||
if (database && user) {
|
||||
const credentials = `${encodeURIComponent(user)}:${encodeURIComponent(password)}@`;
|
||||
return `postgresql://${credentials}${host}:${port}/${database}?schema=${encodeURIComponent(schema)}`;
|
||||
}
|
||||
|
||||
const explicitUrl = process.env.DATABASE_URL?.trim();
|
||||
if (explicitUrl) {
|
||||
return explicitUrl;
|
||||
}
|
||||
|
||||
throw new Error("DATABASE_URL is missing and POSTGRES_DB/POSTGRES_USER are not fully configured");
|
||||
};
|
||||
|
||||
try {
|
||||
process.env.DATABASE_URL = buildDatabaseUrl();
|
||||
} catch (error) {
|
||||
console.error(error instanceof Error ? error.message : String(error));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const child = spawn(args[0], args.slice(1), {
|
||||
stdio: "inherit",
|
||||
shell: true,
|
||||
env: process.env
|
||||
});
|
||||
|
||||
child.on("exit", (code, signal) => {
|
||||
if (signal) {
|
||||
process.kill(process.pid, signal);
|
||||
return;
|
||||
}
|
||||
|
||||
process.exit(code ?? 1);
|
||||
});
|
||||
Reference in New Issue
Block a user