allow public access to / and /index.html

This commit is contained in:
Abel Luck 2026-02-26 16:22:35 +01:00
parent d91f1491f1
commit b052c3f8d8
2 changed files with 13 additions and 9 deletions

View file

@ -14,7 +14,7 @@
packages = forAllSystems (pkgs: {
nix-cache = pkgs.buildNpmPackage {
pname = "nix-cache";
version = "0.1.2";
version = "0.1.3";
src = ./nix-cache;
npmDepsHash = "sha256-bIujU7pZa1ExCZOMOoxsTeLDSF1GuPN/oMSgiMhY/04=";
buildPhase = ''

View file

@ -91,18 +91,22 @@ export default {
return Response.redirect(url.toString(), 301);
}
const authenticated = await authenticate(request, env);
if (!authenticated) {
return new Response('Unauthorized', {
status: 401,
headers: { 'WWW-Authenticate': 'Bearer realm="nix-cache"' },
});
}
if (url.pathname === '/') {
url.pathname = '/index.html';
}
const isPublic = url.pathname === '/index.html';
if (!isPublic) {
const authenticated = await authenticate(request, env);
if (!authenticated) {
return new Response('Unauthorized', {
status: 401,
headers: { 'WWW-Authenticate': 'Bearer realm="nix-cache"' },
});
}
}
const cache = caches.default;
let response = await cache.match(request);
let range: Range | undefined;