Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function lengthHandler(mgr: QueueManager<string>): RouteHandler {
}

function registerRoutes(router: Router, mgr: QueueManager<string>): void {
router.get("/health", () => {
router.get("/health{/}?", () => {
return new Response(JSON.stringify({ status: "ok" }), {
status: 200,
headers: { "Content-Type": "application/json" },
Expand Down
2 changes: 1 addition & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { RateLimiter } from "./rate_limiter.ts";
export type HttpHandler = (request: Request, info?: Deno.ServeHandlerInfo) => Promise<Response> | Response;
export type Middleware = (next: HttpHandler) => HttpHandler;

const HEALTH_PATTERN = new URLPattern({ pathname: "/health" });
const HEALTH_PATTERN = new URLPattern({ pathname: "/health{/}?" });

export function withAuth(apiToken: string): Middleware {
return (next: HttpHandler) => {
Expand Down
7 changes: 7 additions & 0 deletions tests/handler_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ Deno.test("response body: health returns {status:ok} JSON", async () => {
assertEquals(await res.json(), { status: "ok" });
});

Deno.test("response body: health trailing slash returns {status:ok} JSON, no auth required", async () => {
const handler = makeHandler();
const res = await handler(new Request("http://localhost/health/"));
assertEquals(res.status, 200);
assertEquals(await res.json(), { status: "ok" });
});

Deno.test("response body: health POST returns 'Method not allowed'", async () => {
const handler = makeHandler();
const res = await handler(new Request("http://localhost/health", { method: "POST" }));
Expand Down