From 081a2929f7241c61039bab07d4beb14ccf4facf7 Mon Sep 17 00:00:00 2001 From: Leandro Facchinetti Date: Wed, 18 Mar 2020 20:58:41 -0400 Subject: [PATCH] . --- src/index.tsx | 6 ++++++ src/test.ts | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 74aadb9..9e9f9e6 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -30,6 +30,12 @@ export const webServer = express() }) .listen(8443); +export const redirectServer = express() + .all("*", (req, res) => { + res.redirect(301, `https://www.kill-the-newsletter.com${req.originalUrl}`); + }) + .listen(8080); + type Inbox = { name: string; token: string; diff --git a/src/test.ts b/src/test.ts index 5c2509a..55c5d86 100644 --- a/src/test.ts +++ b/src/test.ts @@ -1,8 +1,8 @@ -import { webServer, feedPath } from "."; +import { webServer, redirectServer, feedPath } from "."; import fetch from "node-fetch"; import fs from "fs"; -test("create feed", async () => { +test("webServer", async () => { const response = await fetch("http://localhost:8443", { method: "POST", body: new URLSearchParams({ name: "My Feed" }) @@ -14,6 +14,17 @@ test("create feed", async () => { 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(() => { webServer.close(); + redirectServer.close(); });