Add API authentication

This commit is contained in:
KMKoushik
2024-04-09 17:05:47 +10:00
parent 4d0441791b
commit c34d219561
4 changed files with 62 additions and 20 deletions

View File

@@ -1,7 +1,27 @@
import { OpenAPIHono } from "@hono/zod-openapi";
import { swaggerUI } from "@hono/swagger-ui";
export function getApp() {
return new OpenAPIHono().basePath("/api/v1");
const app = new OpenAPIHono().basePath("/api");
// The OpenAPI documentation will be available at /doc
app.doc("/v1/doc", (c) => ({
openapi: "3.0.0",
info: {
version: "1.0.0",
title: "Unsend API",
},
servers: [{ url: `${new URL(c.req.url).origin}/api` }],
}));
app.openAPIRegistry.registerComponent("securitySchemes", "Bearer", {
type: "http",
scheme: "bearer",
});
app.get("/v1/ui", swaggerUI({ url: "/api/v1/doc" }));
return app;
}
export type PublicAPIApp = ReturnType<typeof getApp>;