Research for the 2026-10-14 build plan found 4/5 first-party sites already carrying the Insights tag, but assumed the mechanism was always a hand-placed <script> in each site's own layout (true for yokharita.com and bidstage.app). It missed that scribase.com, mail.scribase.com and menivor.com get the tag exclusively from the edge injector Worker (inject/wrangler.jsonc's SITE_KEYS) - there is no snippet to find in those repos because there isn't one. Add oxhanatelier.com (+ www.) to the injector as a belt-and-suspenders fallback, same pattern already used for yokharita.com: the injector skips pages that already carry the tag, so this is safe alongside the direct snippet landing in oxhan-atelier's own layout.tsx (companion PR, different repo). Document the full registry and the correction in docs/FIRST-PARTY-SITES.md so the next audit does not have to re-derive this from scratch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
1.9 KiB
JavaScript
52 lines
1.9 KiB
JavaScript
// Railyard Insights tag injector: a pass-through Worker route in front of a
|
|
// site we cannot redeploy cheaply (box-hosted apps behind the tunnel). It adds
|
|
// the cookieless page tag to HTML responses and leaves everything else as is.
|
|
// Sites: hostname -> site key (SITE_KEYS var, JSON). Also fronts yokharita.com and
|
|
// oxhanatelier.com, whose apps ship the tag themselves but are redeployed from
|
|
// other working trees; the tag is added only when the page does not already have it.
|
|
|
|
export const TAG_SRC = "https://insights.ereboslab.com/s.js";
|
|
|
|
export function injectTag(response, siteKey) {
|
|
const type = response.headers.get("content-type") ?? "";
|
|
if (!siteKey || !type.includes("text/html") || response.status >= 300) return response;
|
|
// Skip pages that already carry the tag (sites that ship it in their own layout).
|
|
let present = false;
|
|
const out = new HTMLRewriter()
|
|
.on(`script[src="${TAG_SRC}"]`, {
|
|
element() {
|
|
present = true;
|
|
},
|
|
})
|
|
.on("body", {
|
|
element(el) {
|
|
el.onEndTag((end) => {
|
|
if (!present) end.before(`<script defer src="${TAG_SRC}" data-site="${siteKey}"></script>`, { html: true });
|
|
});
|
|
},
|
|
})
|
|
.transform(response);
|
|
const csp = out.headers.get("content-security-policy");
|
|
if (!csp) return out;
|
|
const headers = new Headers(out.headers);
|
|
const host = new URL(TAG_SRC).origin;
|
|
headers.set(
|
|
"content-security-policy",
|
|
csp.replace(/(script-src[^;]*)/, `$1 ${host}`).replace(/(connect-src[^;]*)/, `$1 ${host}`),
|
|
);
|
|
return new Response(out.body, { status: out.status, statusText: out.statusText, headers });
|
|
}
|
|
|
|
export default {
|
|
async fetch(request, env) {
|
|
const response = await fetch(request);
|
|
let keys = {};
|
|
try {
|
|
keys = JSON.parse(env.SITE_KEYS ?? "{}");
|
|
} catch {
|
|
return response;
|
|
}
|
|
return injectTag(response, keys[new URL(request.url).hostname]);
|
|
},
|
|
};
|