Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions public/_headers
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@

/evidence/*
Cache-Control: public, max-age=3600

# Uptime probe: Blackbox fetches /ratchet every minute. A static file is
# answered before the Worker runs, so the probe costs no CPU (a homepage probe
# renders the page each time). Typed and uncached here so every probe reaches
# the asset store, not an edge cache.
/ratchet
Content-Type: text/plain; charset=utf-8
Cache-Control: no-cache, max-age=0, must-revalidate
X-Robots-Tag: noindex
1 change: 1 addition & 0 deletions public/ratchet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
clank
9 changes: 9 additions & 0 deletions scripts/check-site.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,15 @@ assert.equal(
await installer.text(),
await fs.readFile(new URL('../public/install.sh', import.meta.url), 'utf8'),
);
// The uptime probe is a static file: no Worker CPU per fetch, typed and
// uncached by public/_headers.
const probe = await fetch(new URL('/ratchet', base), { redirect: 'manual' });
assert.equal(probe.status, 200, 'uptime probe');
assert.equal((await probe.text()).trim(), 'clank', 'uptime probe body');
assert.match(probe.headers.get('content-type') || '', /^text\/plain/);
assert.match(probe.headers.get('cache-control') || '', /no-cache/);
assertSecurityHeaders(probe, '/ratchet');
assert.equal(probe.headers.get('x-robots-tag'), 'noindex');
const robots = await fetch(new URL('/robots.txt', base));
assert.equal(robots.status, 200);
assert.match(
Expand Down
12 changes: 12 additions & 0 deletions tests/site.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,15 @@ test('the Worker answers only on fxcss.com and uploads no repository metadata',
);
}
});

test('the uptime probe is a static file with its own headers', () => {
// Blackbox fetches /ratchet every minute. Served before the Worker runs it
// costs no CPU, which a homepage probe does not; public/_headers types it
// and keeps it uncached so every probe reaches the asset store.
assert.equal(read('../public/ratchet').toString().trim(), 'clank');
const headers = read('../public/_headers').toString();
const rule = headers.match(/^\/ratchet\n((?:[ \t]+\S.*\n?)+)/m)?.[1] ?? '';
assert.match(rule, /Content-Type: text\/plain; charset=utf-8/);
assert.match(rule, /Cache-Control: no-cache/);
assert.match(rule, /X-Robots-Tag: noindex/);
});
Loading