This commit is contained in:
Leandro Facchinetti 2020-03-18 20:58:41 -04:00
parent e3ed4b7fb3
commit 081a2929f7
2 changed files with 19 additions and 2 deletions

View File

@ -30,6 +30,12 @@ export const webServer = express()
}) })
.listen(8443); .listen(8443);
export const redirectServer = express()
.all("*", (req, res) => {
res.redirect(301, `https://www.kill-the-newsletter.com${req.originalUrl}`);
})
.listen(8080);
type Inbox = { type Inbox = {
name: string; name: string;
token: string; token: string;

View File

@ -1,8 +1,8 @@
import { webServer, feedPath } from "."; import { webServer, redirectServer, feedPath } from ".";
import fetch from "node-fetch"; import fetch from "node-fetch";
import fs from "fs"; import fs from "fs";
test("create feed", async () => { test("webServer", async () => {
const response = await fetch("http://localhost:8443", { const response = await fetch("http://localhost:8443", {
method: "POST", method: "POST",
body: new URLSearchParams({ name: "My Feed" }) body: new URLSearchParams({ name: "My Feed" })
@ -14,6 +14,17 @@ test("create feed", async () => {
expect(feed).toMatch("My Feed"); expect(feed).toMatch("My Feed");
}); });
test("redirectServer", async () => {
const response = await fetch("http://localhost:8080/something?other", {
redirect: "manual"
});
expect(response.status).toBe(301);
expect(response.headers.get("Location")).toBe(
"https://www.kill-the-newsletter.com/something?other"
);
});
afterAll(() => { afterAll(() => {
webServer.close(); webServer.close();
redirectServer.close();
}); });