From bc6ad87aff15bb24575641b8a4f202182a3a080e Mon Sep 17 00:00:00 2001 From: Ean Milligan Date: Tue, 22 Jul 2025 16:29:28 -0400 Subject: [PATCH] Add api Ping for status testing --- .bruno/Authenticated/General Utility/Ping.bru | 11 +++++++++++ .bruno/Authenticated/General Utility/folder.bru | 8 ++++++++ src/api.ts | 14 +++++++++----- src/endpoints/_index.ts | 12 +++++++----- src/endpoints/gets/apiPing.ts | 16 ++++++++++++++++ 5 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 .bruno/Authenticated/General Utility/Ping.bru create mode 100644 .bruno/Authenticated/General Utility/folder.bru create mode 100644 src/endpoints/gets/apiPing.ts diff --git a/.bruno/Authenticated/General Utility/Ping.bru b/.bruno/Authenticated/General Utility/Ping.bru new file mode 100644 index 0000000..9fa755f --- /dev/null +++ b/.bruno/Authenticated/General Utility/Ping.bru @@ -0,0 +1,11 @@ +meta { + name: Ping + type: http + seq: 1 +} + +get { + url: http://localhost:8166/api/ping + body: none + auth: inherit +} diff --git a/.bruno/Authenticated/General Utility/folder.bru b/.bruno/Authenticated/General Utility/folder.bru new file mode 100644 index 0000000..74f1b02 --- /dev/null +++ b/.bruno/Authenticated/General Utility/folder.bru @@ -0,0 +1,8 @@ +meta { + name: General Utility + seq: 5 +} + +auth { + mode: inherit +} diff --git a/src/api.ts b/src/api.ts index 0d4c920..0021394 100644 --- a/src/api.ts +++ b/src/api.ts @@ -87,6 +87,7 @@ const start = () => { } if (path) { + const lowerCasePath = path.toLowerCase().trim(); if (authenticated) { // Update rate limit details if (updateRateLimitTime) { @@ -97,7 +98,10 @@ const start = () => { // Handle the authenticated request switch (request.method) { case 'GET': - switch (path.toLowerCase()) { + switch (lowerCasePath) { + case '/ping': + case '/ping/': + return endpoints.get.apiPing(); case '/key': case '/key/': return endpoints.get.apiKeyAdmin(query, apiUserid); @@ -113,7 +117,7 @@ const start = () => { } break; case 'POST': - switch (path.toLowerCase()) { + switch (lowerCasePath) { case '/channel/add': case '/channel/add/': return endpoints.post.apiChannelAdd(query, apiUserid); @@ -123,7 +127,7 @@ const start = () => { } break; case 'PUT': - switch (path.toLowerCase()) { + switch (lowerCasePath) { case '/key/ban': case '/key/ban/': case '/key/unban': @@ -149,7 +153,7 @@ const start = () => { } break; case 'DELETE': - switch (path.toLowerCase()) { + switch (lowerCasePath) { case '/key/delete': case '/key/delete/': return endpoints.delete.apiKeyDelete(query, apiUserid, apiUserEmail, apiUserDelCode); @@ -166,7 +170,7 @@ const start = () => { // Handle the unauthenticated request switch (request.method) { case 'GET': - switch (path.toLowerCase()) { + switch (lowerCasePath) { case '/key': case '/key/': return endpoints.get.apiKey(query); diff --git a/src/endpoints/_index.ts b/src/endpoints/_index.ts index 717780f..a992e36 100644 --- a/src/endpoints/_index.ts +++ b/src/endpoints/_index.ts @@ -3,6 +3,7 @@ import { apiKeyDelete } from 'endpoints/deletes/apiKeyDelete.ts'; import { apiChannel } from 'endpoints/gets/apiChannel.ts'; import { apiKey } from 'endpoints/gets/apiKey.ts'; import { apiKeyAdmin } from 'endpoints/gets/apiKeyAdmin.ts'; +import { apiPing } from 'endpoints/gets/apiPing.ts'; import { apiRoll } from 'endpoints/gets/apiRoll.ts'; import { generateWebView } from 'endpoints/gets/webView.ts'; import { heatmapPng } from 'endpoints/gets/heatmapPng.ts'; @@ -18,10 +19,11 @@ export default { apiKeyDelete, }, get: { - apiKey, - apiRoll, - apiKeyAdmin, apiChannel, + apiKey, + apiKeyAdmin, + apiPing, + apiRoll, generateWebView, heatmapPng, }, @@ -29,8 +31,8 @@ export default { apiChannelAdd, }, put: { - apiKeyManage, - apiChannelManageBan, apiChannelManageActive, + apiChannelManageBan, + apiKeyManage, }, }; diff --git a/src/endpoints/gets/apiPing.ts b/src/endpoints/gets/apiPing.ts new file mode 100644 index 0000000..09a09a0 --- /dev/null +++ b/src/endpoints/gets/apiPing.ts @@ -0,0 +1,16 @@ +import { STATUS_CODE, STATUS_TEXT } from '@std/http/status'; + +export const apiPing = (): Response => { + const headers = new Headers(); + headers.append('Content-Type', 'text/json'); + return new Response( + JSON.stringify({ + timestamp: new Date(), + }), + { + status: STATUS_CODE.OK, + statusText: STATUS_TEXT[STATUS_CODE.OK], + headers, + } + ); +};