Hono
This is how your API handler would typically look like:
import { Hono } from "hono";
import * as fs from "node:fs/promises";
import { bootstrapAuth, getUser } from "./auth"; // See below
function startHonoServer() {
bootstrapAuth({
implementation: "real", // or "mock", see: https://docs.oidc-spa.dev/v/v8/integration-guides/backend-token-validation/mock-modes
issuerUri: process.env.OIDC_ISSUER_URI!,
expectedAudience: process.env.OIDC_AUDIENCE
});
const app = new Hono();
app.get("/api/todos", async c => {
const user = await getUser({ req: c.req });
const json = await fs.readFile(`todos_${user.id}.json`, "utf8");
return c.text(json);
});
app.get("/api/todos-for-support/:userId", async c => {
// Will reject the request if user making the request
// doesn't have "support-staff" role
await getUser({ req: c.req, requiredRole: "support-staff" });
const userId = c.req.param("userId");
const json = await fs.readFile(`todos_${userId}.json`, "utf8");
return c.text(json);
});
// ...
}Let's see how to export the utils to make it happen:
Last updated
Was this helpful?