This commit is contained in:
parent
f192ef56ca
commit
f22e678b31
|
@ -7,22 +7,10 @@ import xml2js from "xml2js";
|
|||
import fs from "fs";
|
||||
import cryptoRandomString from "crypto-random-string";
|
||||
|
||||
const webApp = express();
|
||||
if (process.env.NODE_ENV === "production")
|
||||
webApp.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();
|
||||
});
|
||||
webApp.use(express.static("static"));
|
||||
webApp.use(express.urlencoded({ extended: true }));
|
||||
webApp.get("/", (req, res) =>
|
||||
const webApp = express()
|
||||
.use(express.static("static"))
|
||||
.use(express.urlencoded({ extended: true }))
|
||||
.get("/", (req, res) =>
|
||||
res.send(
|
||||
renderHTML(
|
||||
<Layout>
|
||||
|
@ -30,8 +18,8 @@ webApp.get("/", (req, res) =>
|
|||
</Layout>
|
||||
)
|
||||
)
|
||||
);
|
||||
webApp.post("/", (req, res) => {
|
||||
)
|
||||
.post("/", (req, res) => {
|
||||
const inbox: Inbox = { name: req.body.name, token: newToken() };
|
||||
fs.writeFileSync(feedPath(inbox.token), renderXML(Feed(inbox)));
|
||||
res.send(
|
||||
|
@ -41,7 +29,7 @@ webApp.post("/", (req, res) => {
|
|||
</Layout>
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
const emailApp = new SMTPServer({
|
||||
authOptional: true,
|
||||
|
@ -81,6 +69,17 @@ export const webServer = webApp.listen(
|
|||
process.env.NODE_ENV === "production" ? 80 : 8000
|
||||
);
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
webApp.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();
|
||||
});
|
||||
webApp.listen(443);
|
||||
}
|
||||
export const emailServer = emailApp.listen(
|
||||
|
|
Loading…
Reference in New Issue