Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(api): document health route and harden asset auth handling

Tin704376e440b8
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index 86e27663f..c1841ce42 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -128,9 +128,28 @@ export function createApp() {
const api = new Hono<ApiVariables>();
- api.get("/health", (c) => {
- return c.json({ status: "ok" });
- });
+ api.get(
+ "/health",
+ describeRoute({
+ operationId: "getHealth",
+ tags: ["System"],
+ summary: "Health check",
+ security: [],
+ responses: {
+ 200: {
+ description: "API health status",
+ content: {
+ "application/json": {
+ schema: resolver(v.object({ status: v.literal("ok") })),
+ },
+ },
+ },
+ },
+ }),
+ (c) => {
+ return c.json({ status: "ok" });
+ },
+ );
const publicProjectApi = api.get(
"/public-project/:id",
@@ -278,22 +297,51 @@ export function createApp() {
try {
const object = await getPrivateObject(asset.objectKey);
+ const headers: Record<string, string> = {
+ "Cache-Control": asset.isPublic
+ ? "public, max-age=300"
+ : "private, max-age=120",
+ "Content-Disposition": buildContentDisposition(asset.filename),
+ "Content-Type": object.contentType || asset.mimeType,
+ };
+
+ if (object.contentLength !== undefined) {
+ headers["Content-Length"] = object.contentLength.toString();
+ }
+
+ if (object.etag) {
+ headers.ETag = object.etag;
+ }
+
+ if (object.lastModified) {
+ headers["Last-Modified"] = object.lastModified.toUTCString();
+ }
return new Response(object.body as BodyInit, {
- headers: {
- "Cache-Control": asset.isPublic
- ? "public, max-age=300"
- : "private, max-age=120",
- "Content-Disposition": buildContentDisposition(asset.filename),
- "Content-Length": object.contentLength?.toString() || "",
- "Content-Type": object.contentType || asset.mimeType,
- ETag: object.etag || "",
- "Last-Modified": object.lastModified?.toUTCString() || "",
- },
+ headers,
});
} catch (error) {
console.error("Failed to stream asset:", error);
- throw new HTTPException(404, { message: "Asset object not found" });
+ if (
+ (typeof error === "object" &&
+ error !== null &&
+ "statusCode" in error &&
+ error.statusCode === 404) ||
+ (typeof error === "object" &&
+ error !== null &&
+ "code" in error &&
+ (error.code === "NoSuchKey" || error.code === "NotFound")) ||
+ (typeof error === "object" &&
+ error !== null &&
+ "name" in error &&
+ error.name === "NoSuchKey")
+ ) {
+ throw new HTTPException(404, { message: "Asset object not found" });
+ }
+
+ throw new HTTPException(502, {
+ message: "Failed to fetch asset from storage",
+ });
}
},
);
@@ -417,9 +465,19 @@ export function createApp() {
if (error instanceof HTTPException) {
throw error;
}
+
+ if (
+ error instanceof Error &&
+ (error.name === "APIError" || error.name === "AuthError")
+ ) {
+ throw new HTTPException(401, {
+ message: "API key verification failed",
+ });
+ }
+
console.error("API key verification failed:", error);
- throw new HTTPException(401, {
- message: "API key verification failed",
+ throw new HTTPException(500, {
+ message: "Internal Server Error",
});
}
}