mirror of
https://github.com/Feuerhamster/mailform.git
synced 2025-04-29 18:26:53 +02:00
Additional stuff
This commit is contained in:
parent
31e2c67521
commit
1c3ece87fd
4 changed files with 24 additions and 4 deletions
11
README.md
11
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.
|
||||
|
|
|
@ -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 }));
|
||||
|
|
|
@ -7,7 +7,7 @@ export class EmailService {
|
|||
private static targetTransports: Map<string, Transporter> = new Map<string, Transporter>();
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
|
|
@ -5,6 +5,11 @@ export class RateLimiter {
|
|||
|
||||
private static limiters: Map<string, RateLimiterMemory> = new Map<string, RateLimiterMemory>();
|
||||
|
||||
/**
|
||||
* 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<boolean> {
|
||||
|
||||
let rateLimiter: RateLimiterMemory = this.limiters.get(target);
|
||||
|
|
Loading…
Add table
Reference in a new issue