change: removed .html in url
All checks were successful
Deploy on push / deploy (push) Has been skipped
All checks were successful
Deploy on push / deploy (push) Has been skipped
This commit is contained in:
@@ -30,9 +30,9 @@
|
||||
<h1>for vham :3</h1>
|
||||
<p id="haiku">Please enable javascript >.<</p>
|
||||
<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>
|
||||
<a href="rankings.html">rankings</a>
|
||||
<a href="rankings">rankings</a>
|
||||
</p>
|
||||
</header>
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
<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 class="page-links">
|
||||
<a href="index.html">gallery</a>
|
||||
<a href="./">gallery</a>
|
||||
<span class="page-links__separator">/</span>
|
||||
<a href="rankings.html" aria-current="page">rankings</a>
|
||||
<a href="rankings" aria-current="page">rankings</a>
|
||||
</p>
|
||||
</header>
|
||||
|
||||
|
||||
@@ -94,6 +94,15 @@ function resolveRequestPath(pathname) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -113,6 +122,14 @@ function sendText(response, statusCode, body) {
|
||||
response.end(body);
|
||||
}
|
||||
|
||||
function sendRedirect(response, location) {
|
||||
response.writeHead(301, {
|
||||
Location: location,
|
||||
"Cache-Control": "no-store",
|
||||
});
|
||||
response.end();
|
||||
}
|
||||
|
||||
function parseJsonBody(request) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const chunks = [];
|
||||
@@ -194,14 +211,29 @@ async function handleApiRequest(request, response, pathname, options) {
|
||||
function createServer(options) {
|
||||
return http.createServer(async (request, response) => {
|
||||
let pathname;
|
||||
let search;
|
||||
|
||||
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) {
|
||||
sendText(response, 400, "Bad request");
|
||||
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 {
|
||||
if (await handleApiRequest(request, response, pathname, options)) {
|
||||
return;
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
<h1>for vham :3</h1>
|
||||
<p id="haiku">Please enable javascript >.<</p>
|
||||
<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>
|
||||
<a href="rankings.html">rankings</a>
|
||||
<a href="rankings">rankings</a>
|
||||
</p>
|
||||
</header>
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
<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 class="page-links">
|
||||
<a href="index.html">gallery</a>
|
||||
<a href="./">gallery</a>
|
||||
<span class="page-links__separator">/</span>
|
||||
<a href="rankings.html" aria-current="page">rankings</a>
|
||||
<a href="rankings" aria-current="page">rankings</a>
|
||||
</p>
|
||||
</header>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user