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
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ jobs:
- run: npm run typecheck
- run: npm run build
- run: npm run seo:check
# Serve the export with the production nginx config and check status codes, redirects and cache headers.
- name: nginx smoke test
run: |
docker run -d --name vt-nginx -p 8080:80 \
-v "$PWD/deploy/nginx.conf:/etc/nginx/conf.d/default.conf:ro" \
-v "$PWD/build/redirects.map:/etc/nginx/redirects.map:ro" \
-v "$PWD/out:/usr/share/nginx/html:ro" \
nginx:1.27-alpine
for i in $(seq 1 30); do curl -sf -o /dev/null http://127.0.0.1:8080/ && break; sleep 1; done
npm run nginx:smoke -- http://127.0.0.1:8080 || { docker logs vt-nginx | tail -50; exit 1; }
13 changes: 13 additions & 0 deletions deploy/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,26 @@ map $uri $vt_canonical {
include /etc/nginx/redirects.map;
}

# Pages are static, so let the CDN keep HTML for an hour (browsers always revalidate). Cloudflare only stores
# HTML when a Cache Rule makes it eligible; with "respect origin" it then follows s-maxage. Without it every
# crawler fetch reaches the origin (the origin slowed and dropped checks during the 26-27 Oct 2026 recrawl).
map $sent_http_content_type $vt_cache_control {
default "";
~^text/html "public, max-age=0, s-maxage=3600, stale-while-revalidate=86400";
~^text/xml "public, max-age=0, s-maxage=3600";
~^text/plain "public, max-age=0, s-maxage=3600";
}

server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
# Behind Traefik and Cloudflare: keep Location relative so the scheme stays https.
absolute_redirect off;
open_file_cache max=20000 inactive=5m;
open_file_cache_valid 5m;
add_header Cache-Control $vt_cache_control;

gzip on;
gzip_types text/plain text/css application/json application/javascript image/svg+xml;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"og": "tsx scripts/og.ts",
"pipeline:extras": "tsx pipeline/extras.ts",
"indexnow": "node scripts/indexnow.mjs",
"seo:check": "node scripts/seo-check.mjs"
"seo:check": "node scripts/seo-check.mjs",
"nginx:smoke": "node scripts/nginx-smoke.mjs"
},
"dependencies": {
"@fontsource-variable/inter": "^5.3.0",
Expand Down
50 changes: 50 additions & 0 deletions scripts/nginx-smoke.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Smoke-test the nginx config against a running server (default http://127.0.0.1:8080) that serves out/
// with build/redirects.map, the way the Docker image does. Catches redirect loops, broken try_files and
// missing cache headers before they reach Googlebot. Run after `npm run build`.
import { readFileSync } from "node:fs";

const base = (process.argv[2] ?? "http://127.0.0.1:8080").replace(/\/$/, "");
const ORIGIN = "https://vtaircrafts.in";
const paths = [...readFileSync("out/sitemap.xml", "utf8").matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => m[1].slice(ORIGIN.length) || "/");
const regs = paths.filter((p) => p.startsWith("/aircraft/")).map((p) => p.slice("/aircraft/".length));
const problems = [];
let checked = 0;

async function expect(path, want) {
const res = await fetch(base + path, { redirect: "manual" });
checked++;
const got = { status: res.status, location: res.headers.get("location"), cache: res.headers.get("cache-control") ?? "" };
await res.arrayBuffer();
if (got.status !== want.status) problems.push(`${path}: ${got.status}, want ${want.status}${got.location ? ` (Location ${got.location})` : ""}`);
else if (want.location && got.location !== want.location) problems.push(`${path}: Location ${got.location}, want ${want.location}`);
else if (want.cache && !got.cache.includes(want.cache)) problems.push(`${path}: Cache-Control "${got.cache}", want ${want.cache}`);
}

async function run(jobs, width = 32) {
const queue = [...jobs];
await Promise.all(Array.from({ length: width }, async () => { while (queue.length) await queue.shift()(); }));
}

// Every sitemap URL answers 200 itself, never a redirect (a self-redirect here is the 25 Oct 2026 loop).
const jobs = paths.map((p) => () => expect(p, { status: 200, cache: "s-maxage" }));
// Other spellings of a registration 301 to the canonical page with a relative Location.
const step = Math.max(1, Math.floor(regs.length / 300));
for (const reg of regs.filter((_, i) => i % step === 0)) {
const target = `/aircraft/${reg}`;
jobs.push(() => expect(`/aircraft/${reg.toLowerCase()}`, { status: 301, location: target }));
jobs.push(() => expect(`/aircraft/${reg.replace("-", "")}`, { status: 301, location: target }));
jobs.push(() => expect(`/aircraft/${reg.replace("-", "").toLowerCase()}`, { status: 301, location: target }));
}
jobs.push(() => expect("/aircraft/VT-ZZZZ9", { status: 404 }));
jobs.push(() => expect("/robots.txt", { status: 200 }));
jobs.push(() => expect(`/aircraft/${regs[0]}.txt`, { status: 200 }));

await run(jobs);
console.log(`nginx smoke: ${checked} requests against ${base}`);
if (problems.length) {
// Wrong status codes and redirects first; missing cache headers matter less.
problems.sort((a, b) => Number(a.includes("Cache-Control")) - Number(b.includes("Cache-Control")));
console.error(problems.slice(0, 50).join("\n"));
console.error(`${problems.length} problems`);
process.exit(1);
}
Loading