From 99c179b0d89c9e0fabe53526f2c57fe47131326a Mon Sep 17 00:00:00 2001 From: Stig Nygaard Date: Tue, 22 Oct 2024 20:06:07 +0200 Subject: [PATCH] check request method --- main.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.ts b/main.ts index 2ab81d2..fbb9f67 100644 --- a/main.ts +++ b/main.ts @@ -28,7 +28,10 @@ Deno.serve(async (req: Request, info: Deno.ServeHandlerInfo) => { // The "Router"... let response: Response; - if (/^\/proxy-api\/?$/.test(pathname)) { + if (req.method !== 'GET') { + return new Response('Not found', { status: 404, statusText: `Method ${req.method} not supported here`, headers: myHeaders}); + // for supporting other methods, see f.ex: https://youtu.be/p541Je4J_ws?si=-tWmB355467gtFIP + } else if (/^\/proxy-api\/?$/.test(pathname)) { // The "proxy API" - https://lastfm-widgets.deno.dev/proxy-api const result = await proxyApi(url.searchParams, req.headers, info); response = new Response(result.body, {headers: myHeaders, ...result.options});