feat: add a docker compose file
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
## Supabase - DB
|
||||
PUBLIC_SUPABASE_ANON_KEY=
|
||||
PUBLIC_SUPABASE_URL=
|
||||
|
||||
## Cloudflare - Video uploads
|
||||
# Not required - https://cdn.example.com
|
||||
CLOUDFLARE_BUCKET_DOMAIN=
|
||||
|
||||
@@ -9,11 +11,8 @@ CLOUDFLARE_SECRET_ACCESS_KEY=
|
||||
CLOUDFLARE_ACCOUNT_ID=
|
||||
CLOUDFLARE_BUCKET_ID=
|
||||
|
||||
|
||||
# Email
|
||||
SMTP_HOST=
|
||||
SMTP_USER=
|
||||
SMTP_PASSWORD=
|
||||
SMTP_USER_NOTIFY=
|
||||
SMTP_PASSWORD_NOTIFY=
|
||||
SMTP_PORT=
|
||||
ZOHO_TOKEN=
|
||||
|
||||
@@ -3,24 +3,17 @@ const zod = require('zod');
|
||||
const { nodemailerTransporter, zohoClient } = require('../utils/email');
|
||||
const { withEmailTemplate } = require('../utils/withEmailTemplate');
|
||||
|
||||
const router = express.Router();
|
||||
const emailRouter = express.Router();
|
||||
|
||||
let personalTransporter;
|
||||
let defaultTransporter;
|
||||
let transporter;
|
||||
|
||||
// Initialize transporters
|
||||
nodemailerTransporter(true).then((t) => {
|
||||
personalTransporter = t;
|
||||
});
|
||||
nodemailerTransporter(false).then((t) => {
|
||||
defaultTransporter = t;
|
||||
nodemailerTransporter().then((t) => {
|
||||
transporter = t;
|
||||
});
|
||||
|
||||
async function sendWithNodemailer(emailData) {
|
||||
const { from, to, subject, content, isPersonalEmail, replyTo } = emailData;
|
||||
|
||||
const transporter = isPersonalEmail ? personalTransporter : defaultTransporter;
|
||||
|
||||
if (!transporter) {
|
||||
return;
|
||||
}
|
||||
@@ -73,7 +66,7 @@ async function sendWithZoho(emailData) {
|
||||
});
|
||||
}
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
emailRouter.post('/', async (req, res) => {
|
||||
try {
|
||||
const mySchema = zod.array(
|
||||
zod.object({
|
||||
@@ -95,7 +88,7 @@ router.post('/', async (req, res) => {
|
||||
let res;
|
||||
|
||||
try {
|
||||
if (emailData.isPersonalEmail) {
|
||||
if (emailData.isPersonalEmail || !ZOHO_TOKEN) {
|
||||
res = await sendWithNodemailer(emailData);
|
||||
} else {
|
||||
res = await sendWithZoho(emailData);
|
||||
@@ -116,4 +109,4 @@ router.post('/', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
module.exports = emailRouter;
|
||||
|
||||
@@ -1,29 +1,12 @@
|
||||
const { SendMailClient } = require('zeptomail');
|
||||
const nodemailer = require('nodemailer');
|
||||
|
||||
const {
|
||||
ZOHO_TOKEN,
|
||||
SMTP_HOST,
|
||||
SMTP_PORT,
|
||||
SMTP_USER,
|
||||
SMTP_PASSWORD,
|
||||
SMTP_USER_NOTIFY,
|
||||
SMTP_PASSWORD_NOTIFY
|
||||
} = process.env;
|
||||
|
||||
console.log({ ZOHO_TOKEN });
|
||||
const { ZOHO_TOKEN, SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD } = process.env;
|
||||
|
||||
const zohoClient = new SendMailClient({ url: 'api.zeptomail.eu/', token: ZOHO_TOKEN });
|
||||
|
||||
const nodemailerTransporter = async (isPersonal = false) => {
|
||||
if (
|
||||
!SMTP_HOST ||
|
||||
!SMTP_PORT ||
|
||||
!SMTP_USER ||
|
||||
!SMTP_PASSWORD ||
|
||||
!SMTP_USER_NOTIFY ||
|
||||
!SMTP_PASSWORD_NOTIFY
|
||||
) {
|
||||
const nodemailerTransporter = async () => {
|
||||
if (!SMTP_HOST || !SMTP_PORT || !SMTP_USER || !SMTP_PASSWORD) {
|
||||
console.error('SMTP configuration missing');
|
||||
return null;
|
||||
}
|
||||
@@ -34,8 +17,8 @@ const nodemailerTransporter = async (isPersonal = false) => {
|
||||
port: parseInt(SMTP_PORT || '465', 10),
|
||||
secure: true,
|
||||
auth: {
|
||||
user: isPersonal ? SMTP_USER : SMTP_USER_NOTIFY,
|
||||
pass: isPersonal ? SMTP_PASSWORD : SMTP_PASSWORD_NOTIFY
|
||||
user: SMTP_USER,
|
||||
pass: SMTP_PASSWORD
|
||||
}
|
||||
});
|
||||
await transporter.verify();
|
||||
|
||||
Reference in New Issue
Block a user