diff --git a/src/routes.js b/src/routes.js index 51367f9..2a46afb 100644 --- a/src/routes.js +++ b/src/routes.js @@ -9,16 +9,17 @@ router.get("/", async (ctx) => { await ctx.render("home", { BASE_URL }); }); -router.get("/:uuid", async (ctx, next) => { - if (ctx.get("x-requested-with") !== "XMLHttpRequest") { - return await ctx.render("view"); - } +router.get("/:uuid", async (ctx) => { + await ctx.render("view"); +}); +router.get("/data/:uuid", async (ctx, next) => { const gist = getGist(ctx.params.uuid); if (!gist) { return next(); } + ctx.set("Cache-Control", "max-age=2592000"); // 30d ctx.set("X-IV", gist.iv); ctx.body = Buffer.from(gist.cipherText); }); diff --git a/static/view.mjs b/static/view.mjs index 93d4131..8953d17 100644 --- a/static/view.mjs +++ b/static/view.mjs @@ -79,12 +79,7 @@ addEventListener("DOMContentLoaded", async () => { let childElement = document.createElement("code"); try { - const response = await fetch(`/${uuid}`, { - headers: { - "X-Requested-With": "XMLHttpRequest", - }, - }); - + const response = await fetch(`/data/${uuid}`); if (!response.ok) { throw response.status; }