Skip to content

Commit

Permalink
docker compose simplify for local add cloudflare
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Donnellon committed Sep 30, 2024
1 parent 72e427d commit f955c71
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ MAIL_SECURE=true
MAIL_USER=
MAIL_FROM=
MAIL_PASSWORD=
MAIL_IGNORE_TLS=false

# The email address that will receive submitted reports.
REPORT_EMAIL=

# Support email to show on the app
CONTACT_EMAIL=

# Will handle domain name, external access, SSL certs, DDoS protection, and more
# See https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/get-started/create-remote-tunnel/
CF_TUNNEL_TOKEN=
25 changes: 17 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
version: "3"

# This is an example for development. Use real secrets in production.
services:
kutt:
image: kutt/kutt
Expand All @@ -13,25 +12,35 @@ services:
- .env
environment:
DB_HOST: postgres
DB_NAME: kutt
DB_USER: user
DB_PASSWORD: pass
DB_NAME: postgres
DB_USER: postgres
DB_PASSWORD: postgres
REDIS_HOST: redis

redis:
image: redis:6.0-alpine
volumes:
- redis_data:/data
ports:
- "6379:6379"

postgres:
image: postgres:12-alpine
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: kutt
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data

# Will handle domain name, external access, SSL certs, DDoS protection, and more
# See https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/get-started/create-remote-tunnel/
cloudflared:
image: cloudflare/cloudflared:latest
command: tunnel --no-autoupdate run --token ${CF_TUNNEL_TOKEN}

volumes:
redis_data:
postgres_data:
5 changes: 3 additions & 2 deletions server/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ const env = cleanEnv(process.env, {
MAIL_HOST: str(),
MAIL_PORT: num(),
MAIL_SECURE: bool({ default: false }),
MAIL_USER: str(),
MAIL_USER: str({ default: undefined }),
MAIL_FROM: str({ default: "", example: "Kutt <support@kutt.it>" }),
MAIL_PASSWORD: str(),
MAIL_PASSWORD: str({ default: undefined }),
MAIL_IGNORE_TLS: bool({ default: false }),
REPORT_EMAIL: str({ default: "" }),
CONTACT_EMAIL: str({ default: "" })
});
Expand Down
39 changes: 24 additions & 15 deletions server/mail/mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import fs from "fs";
import { resetMailText, verifyMailText, changeEmailText } from "./text";
import { CustomError } from "../utils";
import env from "../env";
import SMTPTransport from "nodemailer/lib/smtp-transport";

const mailConfig = {
const mailConfig: SMTPTransport | SMTPTransport.Options = {
host: env.MAIL_HOST,
port: env.MAIL_PORT,
secure: env.MAIL_SECURE,
ignoreTLS: env.MAIL_IGNORE_TLS,
auth: env.MAIL_USER
? {
user: env.MAIL_USER,
Expand Down Expand Up @@ -43,21 +45,28 @@ const changeEmailTemplate = fs
.replace(/{{site_name}}/gm, env.SITE_NAME);

export const verification = async (user: User) => {
const mail = await transporter.sendMail({
from: env.MAIL_FROM || env.MAIL_USER,
to: user.email,
subject: "Verify your account",
text: verifyMailText
.replace(/{{verification}}/gim, user.verification_token)
.replace(/{{domain}}/gm, env.DEFAULT_DOMAIN)
.replace(/{{site_name}}/gm, env.SITE_NAME),
html: verifyEmailTemplate
.replace(/{{verification}}/gim, user.verification_token)
.replace(/{{domain}}/gm, env.DEFAULT_DOMAIN)
.replace(/{{site_name}}/gm, env.SITE_NAME)
});
try {
const mail = await transporter.sendMail({
from: env.MAIL_FROM || env.MAIL_USER,
to: user.email,
subject: "Verify your account",
text: verifyMailText
.replace(/{{verification}}/gim, user.verification_token)
.replace(/{{domain}}/gm, env.DEFAULT_DOMAIN)
.replace(/{{site_name}}/gm, env.SITE_NAME),
html: verifyEmailTemplate
.replace(/{{verification}}/gim, user.verification_token)
.replace(/{{domain}}/gm, env.DEFAULT_DOMAIN)
.replace(/{{site_name}}/gm, env.SITE_NAME)
});

if (!mail.accepted.length) {
if (!mail.accepted.length) {
throw new CustomError(
"Couldn't send verification email. Try again later."
);
}
} catch (error) {
console.error(error);
throw new CustomError("Couldn't send verification email. Try again later.");
}
};
Expand Down

0 comments on commit f955c71

Please sign in to comment.