From 436a13ff14233d8d32d784625fffefa1e94ff83f Mon Sep 17 00:00:00 2001 From: ClaraCrazy Date: Tue, 17 Sep 2024 20:56:59 +0200 Subject: [PATCH] Update sample --- .gitignore | 1 + application/config.sample.js | 51 ++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 application/config.sample.js diff --git a/.gitignore b/.gitignore index de45fd8..2480aa1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules .idea .DS_Store .vscode +application/config.js \ No newline at end of file diff --git a/application/config.sample.js b/application/config.sample.js new file mode 100644 index 0000000..acbdf6f --- /dev/null +++ b/application/config.sample.js @@ -0,0 +1,51 @@ +// Note: Also update app.json and README.md! + +const config = { + email: { + domains: process.env.EMAIL_DOMAINS, + deleteMailsOlderThanDays: process.env.EMAIL_DELETE_MAILS_OLDER_THAN_DAYS || 2 + }, + imap: { + user: process.env.IMAP_USER, + password: process.env.IMAP_PASSWORD, + host: process.env.IMAP_SERVER, + port: process.env.IMAP_PORT || 993, + tls: process.env.IMAP_TLS || true, + authTimeout: process.env.IMAP_AUTHTIMEOUT || 3000, + refreshIntervalSeconds: process.env.IMAP_REFRESH_INTERVAL_SECONDS || 10 + }, + http: { + port: normalizePort(process.env.HTTP_PORT || '3000'), + branding: process.env.HTTP_BRANDING || ["48hr.email", "CrazyCo", "https://crazyco.xyz"] + }, +} + +if (!config.imap.user || !config.imap.password || !config.imap.host) { + throw new Error('IMAP is not configured. Use IMAP_* ENV vars.') +} + +if (!config.email.domains) { + throw new Error('DOMAINS is not configured. Use ENV vars.') +} + +/** + * Normalize a port into a number, string, or false. + */ + +function normalizePort(val) { + const port = parseInt(val, 10) + + if (isNaN(port)) { + // Named pipe + return val + } + + if (port >= 0) { + // Port number + return port + } + + return false +} + +module.exports = config; \ No newline at end of file