change: removed .html in url
All checks were successful
Deploy on push / deploy (push) Has been skipped

This commit is contained in:
2026-03-23 02:40:49 -07:00
parent 9f60ab3cca
commit a72e4d21d5
5 changed files with 41 additions and 9 deletions

View File

@@ -30,9 +30,9 @@
<h1>for vham :3</h1> <h1>for vham :3</h1>
<p id="haiku">Please enable javascript >.<</p> <p id="haiku">Please enable javascript >.<</p>
<p class="page-links"> <p class="page-links">
<a href="index.html" aria-current="page">gallery</a> <a href="./" aria-current="page">gallery</a>
<span class="page-links__separator">/</span> <span class="page-links__separator">/</span>
<a href="rankings.html">rankings</a> <a href="rankings">rankings</a>
</p> </p>
</header> </header>

View File

@@ -30,9 +30,9 @@
<h1>food power rankings</h1> <h1>food power rankings</h1>
<p>pick the better meal, one pair at a time, and the board updates live in this browser.</p> <p>pick the better meal, one pair at a time, and the board updates live in this browser.</p>
<p class="page-links"> <p class="page-links">
<a href="index.html">gallery</a> <a href="./">gallery</a>
<span class="page-links__separator">/</span> <span class="page-links__separator">/</span>
<a href="rankings.html" aria-current="page">rankings</a> <a href="rankings" aria-current="page">rankings</a>
</p> </p>
</header> </header>

View File

@@ -94,6 +94,15 @@ function resolveRequestPath(pathname) {
return path.join(absolutePath, "index.html"); return path.join(absolutePath, "index.html");
} }
if (
path.extname(absolutePath) === "" &&
!fs.existsSync(absolutePath) &&
fs.existsSync(`${absolutePath}.html`) &&
fs.statSync(`${absolutePath}.html`).isFile()
) {
return `${absolutePath}.html`;
}
return absolutePath; return absolutePath;
} }
@@ -113,6 +122,14 @@ function sendText(response, statusCode, body) {
response.end(body); response.end(body);
} }
function sendRedirect(response, location) {
response.writeHead(301, {
Location: location,
"Cache-Control": "no-store",
});
response.end();
}
function parseJsonBody(request) { function parseJsonBody(request) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const chunks = []; const chunks = [];
@@ -194,14 +211,29 @@ async function handleApiRequest(request, response, pathname, options) {
function createServer(options) { function createServer(options) {
return http.createServer(async (request, response) => { return http.createServer(async (request, response) => {
let pathname; let pathname;
let search;
try { try {
pathname = decodeURIComponent(new URL(request.url || "/", "http://localhost").pathname); const requestUrl = new URL(request.url || "/", "http://localhost");
pathname = decodeURIComponent(requestUrl.pathname);
search = requestUrl.search;
} catch (error) { } catch (error) {
sendText(response, 400, "Bad request"); sendText(response, 400, "Bad request");
return; return;
} }
if (request.method === "GET" || request.method === "HEAD") {
if (pathname === "/index.html") {
sendRedirect(response, `/${search}`);
return;
}
if (pathname.endsWith(".html") && pathname !== "/index.html") {
sendRedirect(response, `${pathname.slice(0, -5)}${search}`);
return;
}
}
try { try {
if (await handleApiRequest(request, response, pathname, options)) { if (await handleApiRequest(request, response, pathname, options)) {
return; return;

View File

@@ -30,9 +30,9 @@
<h1>for vham :3</h1> <h1>for vham :3</h1>
<p id="haiku">Please enable javascript >.<</p> <p id="haiku">Please enable javascript >.<</p>
<p class="page-links"> <p class="page-links">
<a href="index.html" aria-current="page">gallery</a> <a href="./" aria-current="page">gallery</a>
<span class="page-links__separator">/</span> <span class="page-links__separator">/</span>
<a href="rankings.html">rankings</a> <a href="rankings">rankings</a>
</p> </p>
</header> </header>

View File

@@ -30,9 +30,9 @@
<h1>food power rankings</h1> <h1>food power rankings</h1>
<p>pick the better meal, one pair at a time, and the board updates live in this browser.</p> <p>pick the better meal, one pair at a time, and the board updates live in this browser.</p>
<p class="page-links"> <p class="page-links">
<a href="index.html">gallery</a> <a href="./">gallery</a>
<span class="page-links__separator">/</span> <span class="page-links__separator">/</span>
<a href="rankings.html" aria-current="page">rankings</a> <a href="rankings" aria-current="page">rankings</a>
</p> </p>
</header> </header>