Add api Ping for status testing
This commit is contained in:
		
							parent
							
								
									f1025ce129
								
							
						
					
					
						commit
						bc6ad87aff
					
				| 
						 | 
					@ -0,0 +1,11 @@
 | 
				
			||||||
 | 
					meta {
 | 
				
			||||||
 | 
					  name: Ping
 | 
				
			||||||
 | 
					  type: http
 | 
				
			||||||
 | 
					  seq: 1
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					get {
 | 
				
			||||||
 | 
					  url: http://localhost:8166/api/ping
 | 
				
			||||||
 | 
					  body: none
 | 
				
			||||||
 | 
					  auth: inherit
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					meta {
 | 
				
			||||||
 | 
					  name: General Utility
 | 
				
			||||||
 | 
					  seq: 5
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					auth {
 | 
				
			||||||
 | 
					  mode: inherit
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										14
									
								
								src/api.ts
								
								
								
								
							
							
						
						
									
										14
									
								
								src/api.ts
								
								
								
								
							| 
						 | 
					@ -87,6 +87,7 @@ const start = () => {
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (path) {
 | 
					      if (path) {
 | 
				
			||||||
 | 
					        const lowerCasePath = path.toLowerCase().trim();
 | 
				
			||||||
        if (authenticated) {
 | 
					        if (authenticated) {
 | 
				
			||||||
          // Update rate limit details
 | 
					          // Update rate limit details
 | 
				
			||||||
          if (updateRateLimitTime) {
 | 
					          if (updateRateLimitTime) {
 | 
				
			||||||
| 
						 | 
					@ -97,7 +98,10 @@ const start = () => {
 | 
				
			||||||
          // Handle the authenticated request
 | 
					          // Handle the authenticated request
 | 
				
			||||||
          switch (request.method) {
 | 
					          switch (request.method) {
 | 
				
			||||||
            case 'GET':
 | 
					            case 'GET':
 | 
				
			||||||
              switch (path.toLowerCase()) {
 | 
					              switch (lowerCasePath) {
 | 
				
			||||||
 | 
					                case '/ping':
 | 
				
			||||||
 | 
					                case '/ping/':
 | 
				
			||||||
 | 
					                  return endpoints.get.apiPing();
 | 
				
			||||||
                case '/key':
 | 
					                case '/key':
 | 
				
			||||||
                case '/key/':
 | 
					                case '/key/':
 | 
				
			||||||
                  return endpoints.get.apiKeyAdmin(query, apiUserid);
 | 
					                  return endpoints.get.apiKeyAdmin(query, apiUserid);
 | 
				
			||||||
| 
						 | 
					@ -113,7 +117,7 @@ const start = () => {
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
              break;
 | 
					              break;
 | 
				
			||||||
            case 'POST':
 | 
					            case 'POST':
 | 
				
			||||||
              switch (path.toLowerCase()) {
 | 
					              switch (lowerCasePath) {
 | 
				
			||||||
                case '/channel/add':
 | 
					                case '/channel/add':
 | 
				
			||||||
                case '/channel/add/':
 | 
					                case '/channel/add/':
 | 
				
			||||||
                  return endpoints.post.apiChannelAdd(query, apiUserid);
 | 
					                  return endpoints.post.apiChannelAdd(query, apiUserid);
 | 
				
			||||||
| 
						 | 
					@ -123,7 +127,7 @@ const start = () => {
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
              break;
 | 
					              break;
 | 
				
			||||||
            case 'PUT':
 | 
					            case 'PUT':
 | 
				
			||||||
              switch (path.toLowerCase()) {
 | 
					              switch (lowerCasePath) {
 | 
				
			||||||
                case '/key/ban':
 | 
					                case '/key/ban':
 | 
				
			||||||
                case '/key/ban/':
 | 
					                case '/key/ban/':
 | 
				
			||||||
                case '/key/unban':
 | 
					                case '/key/unban':
 | 
				
			||||||
| 
						 | 
					@ -149,7 +153,7 @@ const start = () => {
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
              break;
 | 
					              break;
 | 
				
			||||||
            case 'DELETE':
 | 
					            case 'DELETE':
 | 
				
			||||||
              switch (path.toLowerCase()) {
 | 
					              switch (lowerCasePath) {
 | 
				
			||||||
                case '/key/delete':
 | 
					                case '/key/delete':
 | 
				
			||||||
                case '/key/delete/':
 | 
					                case '/key/delete/':
 | 
				
			||||||
                  return endpoints.delete.apiKeyDelete(query, apiUserid, apiUserEmail, apiUserDelCode);
 | 
					                  return endpoints.delete.apiKeyDelete(query, apiUserid, apiUserEmail, apiUserDelCode);
 | 
				
			||||||
| 
						 | 
					@ -166,7 +170,7 @@ const start = () => {
 | 
				
			||||||
          // Handle the unauthenticated request
 | 
					          // Handle the unauthenticated request
 | 
				
			||||||
          switch (request.method) {
 | 
					          switch (request.method) {
 | 
				
			||||||
            case 'GET':
 | 
					            case 'GET':
 | 
				
			||||||
              switch (path.toLowerCase()) {
 | 
					              switch (lowerCasePath) {
 | 
				
			||||||
                case '/key':
 | 
					                case '/key':
 | 
				
			||||||
                case '/key/':
 | 
					                case '/key/':
 | 
				
			||||||
                  return endpoints.get.apiKey(query);
 | 
					                  return endpoints.get.apiKey(query);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@ import { apiKeyDelete } from 'endpoints/deletes/apiKeyDelete.ts';
 | 
				
			||||||
import { apiChannel } from 'endpoints/gets/apiChannel.ts';
 | 
					import { apiChannel } from 'endpoints/gets/apiChannel.ts';
 | 
				
			||||||
import { apiKey } from 'endpoints/gets/apiKey.ts';
 | 
					import { apiKey } from 'endpoints/gets/apiKey.ts';
 | 
				
			||||||
import { apiKeyAdmin } from 'endpoints/gets/apiKeyAdmin.ts';
 | 
					import { apiKeyAdmin } from 'endpoints/gets/apiKeyAdmin.ts';
 | 
				
			||||||
 | 
					import { apiPing } from 'endpoints/gets/apiPing.ts';
 | 
				
			||||||
import { apiRoll } from 'endpoints/gets/apiRoll.ts';
 | 
					import { apiRoll } from 'endpoints/gets/apiRoll.ts';
 | 
				
			||||||
import { generateWebView } from 'endpoints/gets/webView.ts';
 | 
					import { generateWebView } from 'endpoints/gets/webView.ts';
 | 
				
			||||||
import { heatmapPng } from 'endpoints/gets/heatmapPng.ts';
 | 
					import { heatmapPng } from 'endpoints/gets/heatmapPng.ts';
 | 
				
			||||||
| 
						 | 
					@ -18,10 +19,11 @@ export default {
 | 
				
			||||||
    apiKeyDelete,
 | 
					    apiKeyDelete,
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  get: {
 | 
					  get: {
 | 
				
			||||||
    apiKey,
 | 
					 | 
				
			||||||
    apiRoll,
 | 
					 | 
				
			||||||
    apiKeyAdmin,
 | 
					 | 
				
			||||||
    apiChannel,
 | 
					    apiChannel,
 | 
				
			||||||
 | 
					    apiKey,
 | 
				
			||||||
 | 
					    apiKeyAdmin,
 | 
				
			||||||
 | 
					    apiPing,
 | 
				
			||||||
 | 
					    apiRoll,
 | 
				
			||||||
    generateWebView,
 | 
					    generateWebView,
 | 
				
			||||||
    heatmapPng,
 | 
					    heatmapPng,
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
| 
						 | 
					@ -29,8 +31,8 @@ export default {
 | 
				
			||||||
    apiChannelAdd,
 | 
					    apiChannelAdd,
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  put: {
 | 
					  put: {
 | 
				
			||||||
    apiKeyManage,
 | 
					 | 
				
			||||||
    apiChannelManageBan,
 | 
					 | 
				
			||||||
    apiChannelManageActive,
 | 
					    apiChannelManageActive,
 | 
				
			||||||
 | 
					    apiChannelManageBan,
 | 
				
			||||||
 | 
					    apiKeyManage,
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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,
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
		Loading…
	
		Reference in New Issue