Leandro Facchinetti 2020-12-22 20:50:37 +00:00
parent 08ca42693b
commit 424721b98c
2 changed files with 18 additions and 0 deletions

View File

@ -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())))

14
test.ts
View File

@ -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,
});