feat: add health check response for GET requests in Cloudflare Worker

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Abolfazl
2026-05-02 12:27:26 +03:30
parent 77e69fa36e
commit 39b3e4efa2
+21 -1
View File
@@ -46,8 +46,28 @@ function sanitizeHeaders(h) {
export default {
async fetch(req) {
try {
// Cloudflare dashboard and browsers commonly test a Worker with GET.
// Return a friendly health response so users don't misread it as failure.
if (req.method === "GET") {
return Response.json(
{
ok: true,
status: "healthy",
message: "Everything is OK. Worker is deployed and reachable.",
usage: "Send POST with relay payload for actual proxy requests.",
},
{ status: 200 }
);
}
if (req.method !== "POST") {
return Response.json({ e: "method_not_allowed" }, { status: 405 });
return Response.json(
{
e: "method_not_allowed",
message: "Use POST for relay requests. GET is only a health check.",
},
{ status: 405 }
);
}
const body = await req.json();