Skip to content

Instantly share code, notes, and snippets.

@ertugrulozcan
Created May 23, 2025 20:47
Show Gist options
  • Save ertugrulozcan/81e855b51032b921cfcb6ce594f2822e to your computer and use it in GitHub Desktop.
Save ertugrulozcan/81e855b51032b921cfcb6ce594f2822e to your computer and use it in GitHub Desktop.
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