In Hono, how to use basicAuth with serveStatic?

92 Views Asked by At

When using basicAuth for serveStatic, it throws SIGSEGV error:

error: script "dev" was terminated by signal SIGSEGV (Address boundary error)

It works fine with html methods like app.get

Simple example:

import { Hono } from "hono";
import { basicAuth } from "hono/basic-auth";
import { serveStatic } from "hono/bun";

const app = new Hono();

const auth = basicAuth({
    username: "password",
    password: "password",
});

app.use("/*", auth);

app.use("/static/*", auth, serveStatic({ root: "./" }));

Bun.serve({ port: 8000, fetch: app.fetch });
1

There are 1 best solutions below

0
On

Answering my own question after resolution just for future references:

I tried restarting the computer, did not work. I upgraded the library (bun) and solved the problem, though it was nothing in their release notes about this bug and resolution. So in the future, if you have similar strange problem, try to upgrade/downgrade the referenced library to see if it is caused by an unintended bug in the release you use.