partey_workadventure/back/src/Controller/DebugController.ts

45 lines
1.7 KiB
TypeScript
Raw Normal View History

import {Application, Request, Response} from "express";
import {OK} from "http-status-codes";
import {ADMIN_API_TOKEN, ADMIN_API_URL} from "../Enum/EnvironmentVariable";
import Axios from "axios";
import {DEBUG_MODE} from "../../../front/src/Enum/EnvironmentVariable";
import {IoSocketController} from "_Controller/IoSocketController";
import Flatted from "flatted";
import {stringify} from "circular-json";
export class DebugController {
constructor(private App : Application, private ioSocketController: IoSocketController) {
this.getDump();
}
getDump(){
2020-09-25 15:42:05 +02:00
this.App.get("/dump", (req: Request, res: Response) => {
if (req.query.token !== ADMIN_API_TOKEN) {
return res.status(401).send('Invalid token sent!');
}
return res.status(OK).contentType('application/json').send(stringify(
this.ioSocketController.getWorlds(),
2020-09-25 15:42:05 +02:00
(key: unknown, value: unknown) => {
if(value instanceof Map) {
2020-09-25 15:42:05 +02:00
const obj: any = {}; // eslint-disable-line @typescript-eslint/no-explicit-any
for (const [mapKey, mapValue] of value.entries()) {
obj[mapKey] = mapValue;
}
return obj;
} else if(value instanceof Set) {
2020-09-25 15:42:05 +02:00
const obj: Array<unknown> = [];
for (const [setKey, setValue] of value.entries()) {
obj.push(setValue);
}
return obj;
} else {
return value;
}
}
));
});
}
}