Created
May 23, 2025 20:47
-
-
Save ertugrulozcan/81e855b51032b921cfcb6ce594f2822e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { NextApiRequest, NextApiResponse } from 'next' | |
import { ElasticClusterHealthReport } from '@/models/diagnostics/ElasticClusterHealthReport' | |
import { ErrorResponseModel } from '@/models/ErrorResponseModel' | |
import { HttpMethod } from '@/models/RequestModel' | |
const handler = async (req: NextApiRequest, res: NextApiResponse<ElasticClusterHealthReport | ErrorResponseModel>) => { | |
const response = await fetch(`${process.env.ELASTIC_URL}:9200/_cluster/health`, { | |
method: HttpMethod.GET | |
}); | |
try { | |
const data: ElasticClusterHealthReport | undefined = await response.json() | |
if (response.ok && data) { | |
res.status(response.status).json(data) | |
} | |
else { | |
res.status(response.status).json({ | |
Message: "Unknown error", | |
ErrorCode: "ElasticClusterHealthError", | |
StatusCode: response.status | |
}) | |
} | |
} | |
catch (ex) { | |
console.error(ex) | |
let message: string | |
if (ex instanceof Error) { | |
message = ex.message | |
} | |
else { | |
message = String(ex) | |
} | |
res.status(response.status).json({ | |
Message: message, | |
ErrorCode: "ElasticClusterHealthError", | |
StatusCode: response.status | |
}) | |
} | |
} | |
export default handler; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment