kill-the-newsletter/deployment-example/configuration.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-03-14 00:36:06 +01:00
module.exports = async (require) => {
const path = require("path");
const express = require("express");
const AutoEncrypt = require("@small-tech/auto-encrypt");
2021-03-14 00:47:28 +01:00
const killTheNewsletter = require(".").default;
2021-03-14 00:36:06 +01:00
2021-03-14 00:47:28 +01:00
const { webApplication, emailApplication } = killTheNewsletter(
path.join(__dirname, "data")
);
2021-03-14 00:36:06 +01:00
2021-03-14 00:47:28 +01:00
webApplication.set("url", "https://kill-the-newsletter.com");
2021-03-15 00:13:02 +01:00
webApplication.set("email", "smtp://kill-the-newsletter.com");
2021-03-14 00:47:28 +01:00
webApplication.set("administrator", "mailto:kill-the-newsletter@leafac.com");
2021-03-14 00:36:06 +01:00
const reverseProxy = express();
reverseProxy.use((req, res, next) => {
2021-03-16 02:35:44 +01:00
if (req.hostname !== new URL(webApplication.get("url")).hostname)
return res.redirect(`${webApplication.get("url")}${req.originalUrl}`);
2021-03-14 00:36:06 +01:00
next();
});
2021-03-16 02:42:39 +01:00
reverseProxy.use(webApplication);
2021-03-14 00:36:06 +01:00
AutoEncrypt.https
.createServer(
{
2021-03-14 00:47:28 +01:00
domains: ["kill-the-newsletter.com", "www.kill-the-newsletter.com"],
2021-03-14 00:36:06 +01:00
settingsPath: path.join(__dirname, "data/keys/tls"),
},
reverseProxy
)
.listen(443);
2021-03-15 00:13:02 +01:00
emailApplication.listen(25, () => {
console.log("Email server started");
});
2021-03-14 00:36:06 +01:00
};