Disable debug endpoint by default
This commit is contained in:
1 parent
e43fd30667
commit
32578e95ee
6 files changed
+39
-3
No files matched your search
+9
-1
@@ -27,6 +27,14 @@ import { createStandardResponse } from "./lib/types";
|
||||
*/
|
||||
const app = new Hono<{ Bindings: Env }>();
|
||||
|
||||
function isDebugModeEnabled(value?: string): boolean {
|
||||
if (!value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ["true", "1", "yes", "on"].includes(value.trim().toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Scheduled event handler for periodic maintenance tasks
|
||||
* Executes every 5 minutes as configured in wrangler.jsonc
|
||||
@@ -214,7 +222,7 @@ app
|
||||
*/
|
||||
.post("/debug", async (c) => {
|
||||
// Check if debug mode is enabled via environment variable
|
||||
if (!c.env.DEBUG_MODE) {
|
||||
if (!isDebugModeEnabled(c.env.DEBUG_MODE)) {
|
||||
return c.json(createStandardResponse(404, null), 404);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,18 @@ describe("Main App", () => {
|
||||
});
|
||||
|
||||
describe("POST /debug", () => {
|
||||
it("should return 404 when debug mode is unset", async () => {
|
||||
delete mockEnv.DEBUG_MODE;
|
||||
|
||||
const request = new Request("http://localhost/debug", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ text: "Hello world" }),
|
||||
});
|
||||
const response = await app.fetch(request, mockEnv);
|
||||
|
||||
expect(response.status).toBe(404);
|
||||
});
|
||||
|
||||
it("should return 404 when debug mode is disabled", async () => {
|
||||
mockEnv.DEBUG_MODE = "false";
|
||||
|
||||
@@ -80,6 +92,18 @@ describe("Main App", () => {
|
||||
expect(response.status).toBe(404);
|
||||
});
|
||||
|
||||
it("should return 404 when debug mode is a non-empty falsey-like string", async () => {
|
||||
mockEnv.DEBUG_MODE = "disabled";
|
||||
|
||||
const request = new Request("http://localhost/debug", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ text: "Hello world" }),
|
||||
});
|
||||
const response = await app.fetch(request, mockEnv);
|
||||
|
||||
expect(response.status).toBe(404);
|
||||
});
|
||||
|
||||
it("should provide debug information when enabled", async () => {
|
||||
mockEnv.DEBUG_MODE = "true";
|
||||
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ global.createMockEnv = (): Env => ({
|
||||
PROXY_URLS:
|
||||
"https://test1.example.com/jsonrpc,https://test2.example.com/jsonrpc",
|
||||
PROXY_WEIGHTS: "1,1",
|
||||
DEBUG_MODE: "true",
|
||||
DEBUG_MODE: "false",
|
||||
});
|
||||
|
||||
// Mock Request and Response for Cloudflare Workers environment
|
||||
|
||||
@@ -192,7 +192,7 @@ export function createTestEnvironment() {
|
||||
PROXY_URLS:
|
||||
"https://test1.example.com/jsonrpc,https://test2.example.com/jsonrpc",
|
||||
PROXY_WEIGHTS: "1,1",
|
||||
DEBUG_MODE: "true",
|
||||
DEBUG_MODE: "false",
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
Vendored
+3
@@ -17,6 +17,9 @@ interface Env {
|
||||
|
||||
/** Comma-separated list of proxy weights (optional) */
|
||||
PROXY_WEIGHTS?: string;
|
||||
|
||||
/** Enables the /debug endpoint only when set to an explicit truthy value */
|
||||
DEBUG_MODE?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user