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