Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add healthecheck api endpoint #332

Merged
merged 3 commits into from
Sep 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions apps/web/app/api/health/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { NextRequest, NextResponse } from "next/server";
import fetch from "node-fetch";

import serverConfig from "../../../../../packages/shared/config";

const checkMeilisearchHealth = async () => {
wuast94 marked this conversation as resolved.
Show resolved Hide resolved
if (!serverConfig.meilisearch) {
return { status: "unavailable", message: "Meilisearch is not configured" };
}

try {
const response = await fetch(`${serverConfig.meilisearch.address}/health`, {
headers: {
Authorization: `Bearer ${serverConfig.meilisearch.key}`,
},
});

if (response.ok) {
return { status: "ok", message: "Meilisearch is working" };
} else {
return {
status: "error",
message: "Meilisearch is not responding correctly",
};
}
} catch (error) {
let errorMessage = "An unknown error occurred";
if (error instanceof Error) {
errorMessage = `Meilisearch check failed: ${error.message}`;
}
return { status: "error", message: errorMessage };
}
};

export const GET = async (_req: NextRequest) => {
const webAppStatus = { status: "ok", message: "Web app is working" };
const meilisearchStatus = await checkMeilisearchHealth();

return NextResponse.json({
webApp: webAppStatus,
wuast94 marked this conversation as resolved.
Show resolved Hide resolved
meilisearch: meilisearchStatus,
});
};