From 892c67f5c56343fb78ffee69f0ef5afc40a07dff Mon Sep 17 00:00:00 2001 From: creations Date: Wed, 8 Jan 2025 18:42:07 -0500 Subject: [PATCH] move routes from nsfw to / edit default / --- .../{nsfw => }/[booru]/autocomplete/[tag].ts | 0 src/routes/{nsfw => }/[booru]/id/[id].ts | 0 src/routes/{nsfw => }/[booru]/random.ts | 0 src/routes/{nsfw => }/[booru]/search.ts | 0 src/routes/index.ts | 20 ++++++++++++++----- src/server.ts | 13 +++++++++++- 6 files changed, 27 insertions(+), 6 deletions(-) rename src/routes/{nsfw => }/[booru]/autocomplete/[tag].ts (100%) rename src/routes/{nsfw => }/[booru]/id/[id].ts (100%) rename src/routes/{nsfw => }/[booru]/random.ts (100%) rename src/routes/{nsfw => }/[booru]/search.ts (100%) diff --git a/src/routes/nsfw/[booru]/autocomplete/[tag].ts b/src/routes/[booru]/autocomplete/[tag].ts similarity index 100% rename from src/routes/nsfw/[booru]/autocomplete/[tag].ts rename to src/routes/[booru]/autocomplete/[tag].ts diff --git a/src/routes/nsfw/[booru]/id/[id].ts b/src/routes/[booru]/id/[id].ts similarity index 100% rename from src/routes/nsfw/[booru]/id/[id].ts rename to src/routes/[booru]/id/[id].ts diff --git a/src/routes/nsfw/[booru]/random.ts b/src/routes/[booru]/random.ts similarity index 100% rename from src/routes/nsfw/[booru]/random.ts rename to src/routes/[booru]/random.ts diff --git a/src/routes/nsfw/[booru]/search.ts b/src/routes/[booru]/search.ts similarity index 100% rename from src/routes/nsfw/[booru]/search.ts rename to src/routes/[booru]/search.ts diff --git a/src/routes/index.ts b/src/routes/index.ts index fffcb3f..913d56f 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -1,15 +1,25 @@ const routeDef: RouteDef = { method: "GET", accepts: "*/*", - returns: "text/html", + returns: "application/json", }; async function handler(): Promise { - return new Response("Hello, World!", { - headers: { - "content-type": "text/html", + return Response.json( + { + success: true, + code: 200, + message: + "Welcome to the booru API, check the documentation for more information", + links: { + forgejo: "https://forgejo.creations.works/creations/booru-api", + GitHub: "https://github.com/Creationsss/booru-api", + }, }, - }); + { + status: 200, + }, + ); } export { handler, routeDef }; diff --git a/src/server.ts b/src/server.ts index 5d9ba31..20c4e01 100644 --- a/src/server.ts +++ b/src/server.ts @@ -149,11 +149,22 @@ class ServerHandler { ); } + const headers: Headers = response.headers; + let ip: string | null = server.requestIP(request)?.address || null; + + if (!ip) { + ip = + headers.get("CF-Connecting-IP") || + headers.get("X-Real-IP") || + headers.get("X-Forwarded-For") || + null; + } + logger.info([ `[${request.method}]`, request.url, `${response.status}`, - server.requestIP(request)?.address || "unknown", + `(${ip || "unknown"})`, ]); return response;