fix: add fail-closed preHandler auth check
This commit is contained in:
@@ -11,6 +11,15 @@ async function main() {
|
|||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
server.addHook("preHandler", async (request, reply) => {
|
||||||
|
if (request.url === "/health") return;
|
||||||
|
const auth = request.headers.authorization;
|
||||||
|
if (!auth || !auth.startsWith("Bearer ")) {
|
||||||
|
await reply.code(401).send({ error: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
server.get("/", async () => ({
|
server.get("/", async () => ({
|
||||||
name: "c0py",
|
name: "c0py",
|
||||||
version: "0.1.0",
|
version: "0.1.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user