Skip to content

Commit

Permalink
Cloudflare proxy: handle bare /v1/proxy route as "Hello World".
Browse files Browse the repository at this point in the history
  • Loading branch information
manugoyal committed Nov 1, 2024
1 parent bc912d3 commit 28e3265
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions apis/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ export default {
ctx: ExecutionContext,
): Promise<Response> {
const url = new URL(request.url);
for (const prefix of proxyV1Prefixes) {
if (url.pathname.startsWith(prefix)) {
return handleProxyV1(request, prefix, env, ctx);
}
}
if (url.pathname === "/metrics") {
return handlePrometheusScrape(request, env, ctx);
} else if (url.pathname === "/") {
console.log("URL =", url.pathname);
if (["/", "/v1/proxy", "/v1/proxy/"].includes(url.pathname)) {
return new Response("Hello World!", {
status: 200,
headers: getCorsHeaders(request, originWhitelist(env)),
});
}

if (url.pathname === "/metrics") {
return handlePrometheusScrape(request, env, ctx);
}
for (const prefix of proxyV1Prefixes) {
if (url.pathname.startsWith(prefix)) {
return handleProxyV1(request, prefix, env, ctx);
}
}
return new Response("Not found", {
status: 404,
headers: { "Content-Type": "text/plain" },
Expand Down

0 comments on commit 28e3265

Please sign in to comment.