diff --git a/README.md b/README.md index ad4e620..3a71175 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ > The minimalistic email relay for contact forms and more! This is basically a minimal self-hosted open source alternative to [Formspree](https://formspree.io/) and [SendGrid](https://sendgrid.com/). -Unlike other mail services (that often gives you an API key), this self-hosted mail service is designed to be accessed directly from a frontend. +Unlike other mail services (that often gives you an API key for backends), this self-hosted mail service is designed to be accessed directly from a frontend. ### Features - Access via API or HTML form + redirect @@ -29,6 +29,7 @@ cd mailform docker build -t Feuerhamster/mailform . docker run Feuerhamster/mailform -e PORT=3000 + -e PROXY=true -v /your/custom/path /app/targets ``` @@ -45,8 +46,12 @@ npm run start ## ⚙️Configuration ### Application -To configure the port, simply set the environment variable `PORT` to the port you want to have. -If you want to have your targets in a different directory, you can change that in the `TARGETS_DIR` environment variable. +MailForm can be configured using environment variables. + +**Environment variables:** +- `PORT` The port on which the application starts. If not provided, a random port will be selected. +- `TARGETS_DIR` Path to the directory with your target files. Default is `/targets` of the project root. +- `PROXY` A boolean that enables the "trust proxy" option of Express. **Enable this if you're using MailForm behind a reverse proxy like NGINX!** Default value is false. ### Targets Targets are your different endpoints each with its own rate limits and smtp provider. diff --git a/src/main.ts b/src/main.ts index c2593cb..ecbc938 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,8 +6,13 @@ import routes from "./router"; // Start express app const port = process.env.PORT || 0; +const trustProxy: boolean = (process.env.PROXY === "true"); + const app: Application = express(); +app.set("trust proxy", trustProxy); +app.set("x-powered-by", false); + // Middlewares app.use(express.json()); app.use(express.urlencoded({ extended: true })); diff --git a/src/services/email.ts b/src/services/email.ts index f69a387..9cb8373 100644 --- a/src/services/email.ts +++ b/src/services/email.ts @@ -7,7 +7,7 @@ export class EmailService { private static targetTransports: Map = new Map(); /** - * Register a mail target in the email service + * Register a target in the email service * @param targetName (file-)name of an existing and loaded target * @param smtpURL A valid SMTP(S) URL */ diff --git a/src/services/rateLimiter.ts b/src/services/rateLimiter.ts index 3b9c353..db8ef6d 100644 --- a/src/services/rateLimiter.ts +++ b/src/services/rateLimiter.ts @@ -5,6 +5,11 @@ export class RateLimiter { private static limiters: Map = new Map(); + /** + * Register a target in the rate limiter service + * @param targetName Name of the target + * @param limits Rate limit configuration for target + */ public static registerTarget(targetName: string, limits: TargetRateLimit): void { this.limiters.set(targetName, new RateLimiterMemory({ @@ -14,6 +19,11 @@ export class RateLimiter { } + /** + * Consume one point of a target's rate limiter + * @param target (file-)name of a target + * @param identifier Rate limiter identifier (ip address) + */ public static async consume(target, identifier): Promise { let rateLimiter: RateLimiterMemory = this.limiters.get(target);