diff --git a/index.ts b/index.ts index 3cc0623..1292d83 100644 --- a/index.ts +++ b/index.ts @@ -18,6 +18,10 @@ export const ISSUE_REPORT = process.env.ISSUE_REPORT ?? "mailto:kill-the-newsletter@leafac.com"; export const webServer = express() + .use(["/feeds", "/alternate"], (req, res, next) => { + res.header("X-Robots-Tag", "noindex"); + next(); + }) .use(express.static("static")) .use(express.urlencoded({ extended: true })) .get("/", (req, res) => res.send(layout(newInbox()))) diff --git a/test.ts b/test.ts index 0e11e32..8c063e1 100644 --- a/test.ts +++ b/test.ts @@ -221,6 +221,20 @@ describe("receive email", () => { }); }); +test("‘noindex’ header", async () => { + const identifier = await createFeed(); + const feed = await getFeed(identifier); + const entry = feed.querySelector("feed > entry:first-of-type")!; + const alternatePath = entry.querySelector("link")!.getAttribute("href")!; + expect((await webClient.get(`/`)).headers["x-robots-tag"]).toBeUndefined(); + expect( + (await webClient.get(`/feeds/${identifier}.xml`)).headers["x-robots-tag"] + ).toBe("noindex"); + expect((await webClient.get(alternatePath)).headers["x-robots-tag"]).toBe( + "noindex" + ); +}); + const webClient = axios.create({ baseURL: BASE_URL, });