Skip to content

Commit

Permalink
Frontend uses TMT log address from backend
Browse files Browse the repository at this point in the history
  • Loading branch information
JensForstmann committed Nov 6, 2023
1 parent fe8ee47 commit ba63422
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
16 changes: 16 additions & 0 deletions backend/src/configController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Controller, Get, NoSecurity, Route, Security } from '@tsoa/runtime';
import { TMT_LOG_ADDRESS } from '.';

@Route('/api/config')
@Security('bearer_token')
export class ConfigController extends Controller {
@Get()
@NoSecurity()
async getConfig(): Promise<{
tmtLogAddress: string | null;
}> {
return {
tmtLogAddress: TMT_LOG_ADDRESS,
};
}
}
26 changes: 26 additions & 0 deletions backend/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { GameServersController } from './gameServersController';
import { PresetsController } from './presetsController';
// 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
import { DebugController } from './debugController';
// 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
import { ConfigController } from './configController';
import { expressAuthentication } from './auth';
// @ts-ignore - no great way to install types from subpackage
const promiseAny = require('promise.any');
Expand Down Expand Up @@ -1845,6 +1847,30 @@ export function RegisterRoutes(app: Router) {
}
);
// 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
app.get(
'/api/config',
...fetchMiddlewares<RequestHandler>(ConfigController),
...fetchMiddlewares<RequestHandler>(ConfigController.prototype.getConfig),

function ConfigController_getConfig(request: any, response: any, next: any) {
const args = {};

// 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

let validatedArgs: any[] = [];
try {
validatedArgs = getValidatedArgs(args, request, response);

const controller = new ConfigController();

const promise = controller.getConfig.apply(controller, validatedArgs as any);
promiseHandler(controller, promise, response, undefined, next);
} catch (err) {
return next(err);
}
}
);
// 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

// 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

Expand Down
28 changes: 28 additions & 0 deletions backend/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2990,6 +2990,34 @@
],
"parameters": []
}
},
"/api/config": {
"get": {
"operationId": "GetConfig",
"responses": {
"200": {
"description": "Ok",
"content": {
"application/json": {
"schema": {
"properties": {
"tmtLogAddress": {
"type": "string",
"nullable": true
}
},
"required": [
"tmtLogAddress"
],
"type": "object"
}
}
}
}
},
"security": [],
"parameters": []
}
}
},
"servers": [
Expand Down
23 changes: 22 additions & 1 deletion frontend/src/pages/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export const CreatePage: Component = () => {
},
matchEndAction: 'NONE',
mode: 'SINGLE',
tmtLogAddress: window.location.protocol + '//' + window.location.host,
tmtLogAddress: undefined, // will be set in onMount()
canClinch: true,
});

Expand All @@ -217,10 +217,19 @@ export const CreatePage: Component = () => {
}
});

const setTmtLogAddress = async () => {
fetcher<{ tmtLogAddress: string | null }>('GET', `/api/config`).then((resp) => {
const tmtLogAddress =
resp?.tmtLogAddress ?? window.location.protocol + '//' + window.location.host;
setMatchCreateDto('tmtLogAddress', tmtLogAddress);
});
};

onMount(() => {
if (electionStepsRef) {
autoAnimate(electionStepsRef);
}
setTmtLogAddress();
});

const setMatchDataFromPreset = (presetId: string) => {
Expand Down Expand Up @@ -576,6 +585,18 @@ export const CreatePage: Component = () => {
{t('Quit server via Rcon after match end')}
</option>
</SelectInput>
<TextInput
label={t('TMT Log Address')}
labelTopRight={t('HTTP log receiver from the perspective of the game server')}
value={matchCreateDto.tmtLogAddress ?? ''}
onInput={(e) => setMatchCreateDto('tmtLogAddress', e.currentTarget.value)}
/>
<ToggleInput
label={t('Can Clinch')}
labelTopRight={t('Ends match series after a map if a winner is determined')}
checked={matchCreateDto.canClinch}
onInput={(e) => setMatchCreateDto('canClinch', e.currentTarget.checked)}
/>

<TextArea
label={t('Match Init Payload Data (JSON)')}
Expand Down

0 comments on commit ba63422

Please sign in to comment.