Add api Ping for status testing

This commit is contained in:
Ean Milligan 2025-07-22 16:29:28 -04:00
parent f1025ce129
commit bc6ad87aff
5 changed files with 51 additions and 10 deletions

View File

@ -0,0 +1,11 @@
meta {
name: Ping
type: http
seq: 1
}
get {
url: http://localhost:8166/api/ping
body: none
auth: inherit
}

View File

@ -0,0 +1,8 @@
meta {
name: General Utility
seq: 5
}
auth {
mode: inherit
}

View File

@ -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);

View File

@ -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,
},
};

View File

@ -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,
}
);
};