Skip to content

Commit

Permalink
Add debug page to frontend: /debug
Browse files Browse the repository at this point in the history
  • Loading branch information
JensForstmann committed May 3, 2024
1 parent b4bc3c3 commit 068eed8
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 45 deletions.
2 changes: 1 addition & 1 deletion backend/src/configController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Controller, Get, NoSecurity, Route, Security } from '@tsoa/runtime';
import { TMT_LOG_ADDRESS } from '.';
import { IConfig } from '../../common/types/config';
import { IConfig } from '../../common';

@Route('/api/config')
@Security('bearer_token')
Expand Down
5 changes: 3 additions & 2 deletions backend/src/debugController.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Controller, Get, Route, Security } from '@tsoa/runtime';
import * as WebSocket from './webSocket';
import { PORT, TMT_LOG_ADDRESS, VERSION } from '.';
import { IDebugResponse } from '../../common';
import { Settings } from './settings';
import { STORAGE_FOLDER } from './storage';
import * as WebSocket from './webSocket';

@Route('/api/debug')
@Security('bearer_token')
Expand All @@ -16,7 +17,7 @@ export class DebugController extends Controller {
}

@Get('/')
async getInfos() {
async getInfos(): Promise<IDebugResponse> {
return {
tmtVersion: VERSION,
tmtStorageFolder: STORAGE_FOLDER,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/presets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { generate as shortUuid } from 'short-uuid';
import { IPreset, IPresetCreateDto, IPresetUpdateDto } from '../../common/types/preset';
import { IPreset, IPresetCreateDto, IPresetUpdateDto } from '../../common';
import * as Storage from './storage';

const FILE_NAME = 'presets.json';
Expand Down
2 changes: 1 addition & 1 deletion backend/src/presetsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Security,
SuccessResponse,
} from '@tsoa/runtime';
import { IPreset, IPresetCreateDto } from '../../common/types/preset';
import { IPreset, IPresetCreateDto } from '../../common';
import { ExpressRequest, IAuthResponse } from './auth';
import * as Presets from './presets';

Expand Down
25 changes: 25 additions & 0 deletions backend/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,31 @@ const models: TsoaRoute.Models = {
additionalProperties: false,
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
IDebugResponse: {
dataType: 'refObject',
properties: {
tmtVersion: {
dataType: 'union',
subSchemas: [{ dataType: 'string' }, { dataType: 'enum', enums: [null] }],
required: true,
},
tmtStorageFolder: { dataType: 'string', required: true },
tmtPort: {
dataType: 'union',
subSchemas: [{ dataType: 'string' }, { dataType: 'double' }],
required: true,
},
tmtLogAddress: {
dataType: 'union',
subSchemas: [{ dataType: 'string' }, { dataType: 'enum', enums: [null] }],
required: true,
},
tmtSayPrefix: { dataType: 'string', required: true },
webSockets: { dataType: 'array', array: { dataType: 'any' }, required: true },
},
additionalProperties: false,
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
IConfig: {
dataType: 'refObject',
properties: {
Expand Down
82 changes: 44 additions & 38 deletions backend/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,49 @@
"type": "object",
"additionalProperties": false
},
"IDebugResponse": {
"properties": {
"tmtVersion": {
"type": "string",
"nullable": true
},
"tmtStorageFolder": {
"type": "string"
},
"tmtPort": {
"anyOf": [
{
"type": "string"
},
{
"type": "number",
"format": "double"
}
]
},
"tmtLogAddress": {
"type": "string",
"nullable": true
},
"tmtSayPrefix": {
"type": "string"
},
"webSockets": {
"items": {},
"type": "array"
}
},
"required": [
"tmtVersion",
"tmtStorageFolder",
"tmtPort",
"tmtLogAddress",
"tmtSayPrefix",
"webSockets"
],
"type": "object",
"additionalProperties": false
},
"IConfig": {
"properties": {
"tmtLogAddress": {
Expand Down Expand Up @@ -2998,44 +3041,7 @@
"content": {
"application/json": {
"schema": {
"properties": {
"webSockets": {
"items": {},
"type": "array"
},
"tmtSayPrefix": {
"type": "string"
},
"tmtLogAddress": {
"type": "string"
},
"tmtPort": {
"anyOf": [
{
"type": "string"
},
{
"type": "number",
"format": "double"
}
]
},
"tmtStorageFolder": {
"type": "string"
},
"tmtVersion": {
"type": "string"
}
},
"required": [
"webSockets",
"tmtSayPrefix",
"tmtLogAddress",
"tmtPort",
"tmtStorageFolder",
"tmtVersion"
],
"type": "object"
"$ref": "#/components/schemas/IDebugResponse"
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions common/types/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface IDebugResponse {
tmtVersion: string | null;
tmtStorageFolder: string;
tmtPort: string | number;
tmtLogAddress: string | null;
tmtSayPrefix: string;
webSockets: any[];
}
3 changes: 3 additions & 0 deletions common/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './config';
export * from './debug';
export * from './election';
export * from './electionStep';
export * from './events';
Expand All @@ -6,6 +8,7 @@ export * from './log';
export * from './match';
export * from './matchMap';
export * from './player';
export * from './preset';
export * from './stuff';
export * from './team';
export * from './webSocket';
5 changes: 3 additions & 2 deletions frontend/src/components/CreateUpdateMatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import autoAnimate from '@formkit/auto-animate';
import { Component, For, Match, Show, Switch, createEffect, createSignal, onMount } from 'solid-js';
import { createStore } from 'solid-js/store';
import {
IConfig,
IElectionStep,
IMatchCreateDto,
IMatchResponse,
IMatchUpdateDto,
IPreset,
IPresetCreateDto,
TMatchEndAction,
TMatchMode,
TTeamAB,
getOtherTeamAB,
} from '../../../common';
import { IConfig } from '../../../common/types/config';
import { IPreset, IPresetCreateDto } from '../../../common/types/preset';
import {
SvgAdd,
SvgDelete,
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Route, Router } from '@solidjs/router';
import { render } from 'solid-js/web';
import { App } from './App';
import { CreatePage } from './pages/create';
import { DebugPage } from './pages/debug';
import { GameServersPage } from './pages/gameServers';
import { LoginPage } from './pages/login';
import { LogoutPage } from './pages/logout';
Expand All @@ -23,6 +24,7 @@ render(
<Route path="/login" component={LoginPage} />
<Route path="/logout" component={LogoutPage} />
<Route path={['/', '/create']} component={CreatePage} />
<Route path="/debug" component={DebugPage} />
<Route path="/*" component={NotFoundPage} />
</Router>
),
Expand Down
20 changes: 20 additions & 0 deletions frontend/src/pages/debug.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Component, createEffect, createSignal } from 'solid-js';
import { Card } from '../components/Card';
import { createFetcher } from '../utils/fetcher';
import { IDebugResponse } from '../../../common';

export const DebugPage: Component = () => {
const fetcher = createFetcher();
const [debugData, setDebugData] = createSignal<IDebugResponse>();
createEffect(() => {
fetcher<IDebugResponse>('GET', '/api/debug').then((debug) => {
setDebugData(debug);
});
});

return (
<Card>
<pre>{JSON.stringify(debugData(), null, 4)}</pre>
</Card>
);
};

0 comments on commit 068eed8

Please sign in to comment.