This commit is contained in:
parent
4131c21645
commit
6dcd96ab06
|
@ -8,10 +8,22 @@ import { Builder, Parser } from "xml2js";
|
|||
import fs from "fs";
|
||||
import cryptoRandomString from "crypto-random-string";
|
||||
|
||||
const webApp = express()
|
||||
.use(express.static("static"))
|
||||
.use(express.urlencoded({ extended: true }))
|
||||
.get("/", (req, res) =>
|
||||
const app = express();
|
||||
if (process.env.NODE_ENV === "production")
|
||||
app.use((req, res, next) => {
|
||||
if (
|
||||
req.protocol !== "https" ||
|
||||
req.hostname !== "www.kill-the-newsletter.com"
|
||||
)
|
||||
return res.redirect(
|
||||
301,
|
||||
`https://www.kill-the-newsletter.com${req.originalUrl}`
|
||||
);
|
||||
next();
|
||||
});
|
||||
app.use(express.static("static"));
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
app.get("/", (req, res) =>
|
||||
res.send(
|
||||
renderHTML(
|
||||
<Layout>
|
||||
|
@ -19,8 +31,8 @@ const webApp = express()
|
|||
</Layout>
|
||||
)
|
||||
)
|
||||
)
|
||||
.post("/", (req, res) => {
|
||||
);
|
||||
app.post("/", (req, res) => {
|
||||
const inbox: Inbox = { name: req.body.name, token: newToken() };
|
||||
fs.writeFileSync(feedPath(inbox.token), renderXML(Feed(inbox)));
|
||||
res.send(
|
||||
|
@ -65,29 +77,13 @@ export const emailServer = new SMTPServer({
|
|||
}
|
||||
});
|
||||
|
||||
export let developmentWebServer: Server;
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
const productionWebApp = express()
|
||||
.use((req, res, next) => {
|
||||
if (
|
||||
req.protocol !== "https" ||
|
||||
req.hostname !== "www.kill-the-newsletter.com"
|
||||
)
|
||||
return res.redirect(
|
||||
301,
|
||||
`https://www.kill-the-newsletter.com${req.originalUrl}`
|
||||
export const webServer = app.listen(
|
||||
process.env.NODE_ENV === "production" ? 80 : 8000
|
||||
);
|
||||
next();
|
||||
})
|
||||
.use(webApp);
|
||||
productionWebApp.listen(80);
|
||||
productionWebApp.listen(443);
|
||||
emailServer.listen(25);
|
||||
} else {
|
||||
developmentWebServer = webApp.listen(8000);
|
||||
emailServer.listen(2525);
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
app.listen(443);
|
||||
}
|
||||
emailServer.listen(process.env.NODE_ENV === "production" ? 25 : 2525);
|
||||
|
||||
type Inbox = {
|
||||
name: string;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { developmentWebServer, emailServer, feedPath, feedEmail } from ".";
|
||||
import { webServer, emailServer, feedPath, feedEmail } from ".";
|
||||
import { createTransport } from "nodemailer";
|
||||
import fetch from "node-fetch";
|
||||
import fs from "fs";
|
||||
|
@ -58,7 +58,7 @@ describe("receive email", () => {
|
|||
});
|
||||
|
||||
afterAll(() => {
|
||||
developmentWebServer.close();
|
||||
webServer.close();
|
||||
emailServer.close(() => {});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue