Skip to content
Open
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
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,11 @@ jobs:
curl -fsS http://localhost:8350/ | grep -q 'Play your Stems back into the Mixer'
curl -fsSI http://localhost:8350/ | grep -qi 'content-security-policy'
test "$(curl -s -o /dev/null -w '%{http_code}' http://localhost:8350/nope)" = 404
curl -s http://localhost:8350/nope | grep -q 'Page not found'
# The 404 page asked for by name, and a folder, are a 404 too: not a page, and not a redirect.
for path in /404 /404.html /_not-found /_not-found.html /images /_next; do
test "$(curl -s -o /dev/null -w '%{http_code}' "http://localhost:8350$path")" = 404
done
test "$(curl -s -o /dev/null -w '%{http_code}' http://localhost:8350/favicon.ico)" = 200
test "$(curl -s -o /dev/null -w '%{http_code}' -H 'Host: www.soundcheckplayer.app' http://localhost:8350/)" = 301
docker rm -f site
1 change: 1 addition & 0 deletions website/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ changes.
| What | Where |
| --- | --- |
| The page | `app/page.tsx` |
| The 404 page (exported as `404.html`; nginx serves it with a 404 status) | `app/not-found.tsx` |
| Title, description, theme color | `app/layout.tsx` |
| Share image (1200 x 630) and its alt text | `public/og-image.png`, `lib/metadata.ts` |
| Styles and tokens (Dark first, light when the system is light) | `app/globals.css` |
Expand Down
Binary file added website/app/favicon.ico
Binary file not shown.
31 changes: 31 additions & 0 deletions website/app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { Metadata } from "next";
import { SITE_NAME } from "@/lib/site";

// Exported as 404.html, which nginx serves with a 404 status for any address that is not a page. Next adds
// <meta name="robots" content="noindex"> itself. No canonical address and no share card: the layout's describe the
// home page, and this page is served at whatever address was asked for.
export const metadata: Metadata = {
title: { absolute: `Page not found - ${SITE_NAME}` },
description: "There is no page at this address.",
alternates: { canonical: null },
openGraph: null,
twitter: null,
};

export default function NotFound() {
return (
<main id="main" tabIndex={-1}>
<section>
<div className="wrap narrow">
<h1>Page not found</h1>
<p>There is no page at this address.</p>
<p>
<a href="/" className="button">
Go to the home page
</a>
</p>
</div>
</section>
</main>
);
}
16 changes: 15 additions & 1 deletion website/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,21 @@ server {
return 301 /$html_query;
}

# The 404 page is only ever the answer to a missing address: asked for by name it is a 404 too, not a page.
# "internal" still lets error_page serve it.
location = /404.html { internal; }
location = /404 { return 404; }
location = /_not-found { return 404; }
location = /_not-found.html { return 404; }

# The home page. It has its own rule because the catch-all below no longer tries folders.
location = / {
try_files /index.html =404;
}

location / {
try_files $uri $uri.html $uri/ =404;
# No "$uri/": a folder such as /images or /_next is not a page. With it, nginx redirected /images to
# /images/, which answered 403.
try_files $uri $uri.html =404;
}
}
55 changes: 55 additions & 0 deletions website/tests/notFound.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { existsSync, readFileSync } from "node:fs";
import path from "node:path";
import { renderToStaticMarkup } from "react-dom/server";
import NotFound, { metadata } from "@/app/not-found";

const ROOT = path.resolve(__dirname, "..");
const html = renderToStaticMarkup(<NotFound />);
const nginx = readFileSync(path.join(ROOT, "nginx.conf"), "utf8");

describe("the not-found page", () => {
it("says the page is missing, in one heading, and links to the home page", () => {
expect(html.match(/<h1/g)).toHaveLength(1);
expect(html).toMatch(/<h1[^>]*>Page not found<\/h1>/);
expect(html).toMatch(/<a[^>]*href="\/"[^>]*>Go to the home page<\/a>/);
expect(html).toMatch(/<main[^>]*id="main"/);
});

it("has its own title, and no canonical address or share card of the home page", () => {
expect(metadata.title).toEqual({ absolute: "Page not found - SoundcheckPlayer" });
expect(metadata.alternates).toEqual({ canonical: null });
expect(metadata.openGraph).toBeNull();
expect(metadata.twitter).toBeNull();
});

it("uses plain sentences: no exclamation points or em dashes", () => {
expect(html).not.toMatch(/!|—/);
});
});

describe("nginx, for addresses that are not pages", () => {
it("answers /404 and /_not-found with a 404 status, not the 404 page as a normal page", () => {
expect(nginx).toMatch(/location = \/404\s*\{\s*return 404;\s*\}/);
expect(nginx).toMatch(/location = \/_not-found\s*\{\s*return 404;\s*\}/);
expect(nginx).toMatch(/location = \/404\.html\s*\{\s*internal;\s*\}/);
});

it("does not try a folder, so /images and /_next are a 404 and not a redirect to a 403", () => {
const catchAll = nginx.match(/location \/ \{[\s\S]*?\}/)?.[0] ?? "";
expect(catchAll).toMatch(/try_files \$uri \$uri\.html =404;/);
});

// Without "$uri/" the catch-all no longer finds the home page (CI's Docker step caught it), so "/" has its own rule.
it("serves the home page from index.html with a rule of its own", () => {
expect(nginx).toMatch(/location = \/ \{\s*try_files \/index\.html =404;\s*\}/);
});
});

describe("the favicon", () => {
it("is also served at /favicon.ico, where crawlers ask for it", () => {
const ico = readFileSync(path.join(ROOT, "app", "favicon.ico"));
expect(existsSync(path.join(ROOT, "app", "favicon.ico"))).toBe(true);
// An .ico file starts 00 00 01 00.
expect([...ico.subarray(0, 4)]).toEqual([0, 0, 1, 0]);
});
});
Loading