I’m using Quartz to create this personal website. It’s nice software, but there’s one quirk with it that made it difficult for me to get started. Quartz documentation shows that it supports the following self-hosting methods
- Caddy
- Apache2
- Nginx
What about serving on Bunny Storage, my preferred hosting solution? I build my quartz site using npx quartz build then I push it to Bunny via FTP. The files then get served via my domain name. Quartz doesn’t support Bunny static hosting out of the box for one big reason— Quartz doesn’t create index.html routes for every page like other static site generators do. Instead, Quartz relies on request rewrite rules. This leads to lots of 404s when I’m expecting to see a rendered html page.
Long story short, I was able to use a Bunny origin Middleware Script to rewrite paths in a way that are compatible with Quartz—
import * as BunnySDK from "https://esm.sh/@bunny.net/edgescript-sdk@0.11.2";
async function onOriginRequest(context: { request: Request }) {
const url = new URL(context.request.url);
let pathname = url.pathname;
// Ignore assets and files with extensions
if (pathname.match(/\.[a-zA-Z0-9]+$/)) {
return;
}
// Handle directory requests: /foo/ → /foo/index.html
if (pathname.endsWith("/")) {
url.pathname = `${pathname}index.html`;
}
// Handle extensionless routes: /foo → /foo.html
else {
url.pathname = `${pathname}.html`;
}
// Rewrite the request
return new Request(url.toString(), context.request);
}
async function onOriginResponse(context: { request: Request; response: Response }) {
// Optional: add headers for debugging
context.response.headers.append("X-Quartz-Rewrite", "true");
}
BunnySDK.net.http
.servePullZone()
.onOriginRequest(onOriginRequest)
.onOriginResponse(onOriginResponse);The X-Quartz-Rewrite header was helpful. After deploying the script, I checked my browser’s network tab to verify that the edge script was working.
