fix worlds endpoint

This commit is contained in:
_Bastler 2021-09-28 10:29:30 +02:00
parent 99619cf140
commit 9b84c94579

View File

@ -109,19 +109,15 @@ export class MapController extends BaseController {
res.onAborted(() => {
console.warn("/message request was aborted");
});
const { userIdentify, token } = parse(req.getQuery());
const { token } = parse(req.getQuery());
try {
//verify connected by token
if (token != undefined) {
try {
const authTokenData: AuthTokenData = jwtTokenManager.verifyJWTToken(token as string, false);
if (authTokenData.hydraAccessToken == undefined) {
throw Error("Token cannot to be check on Hydra");
}
jwtTokenManager.verifyJWTToken(token as string, false);
const result: any[] = [];
for (const room of socketManager.getWorlds().values()) {
const world : any = {};
const world: any = {};
world.roomId = room.roomUrl;
world.player = [];
for (const listener of room.getListeners()) {
@ -135,15 +131,21 @@ export class MapController extends BaseController {
result.push(world);
}
return res
.writeStatus("200 OK")
.writeHeader("Content-Type", "application/json")
.end(
JSON.stringify({ worlds: result })
);
res.writeStatus("200 OK");
res.writeHeader("Content-Type", "application/json");
this.addCorsHeaders(res);
res.end(
JSON.stringify({ worlds: result })
);
} catch (error) {
return this.errorToResponse(error, res);
res.writeStatus("403 FORBIDDEN");
this.addCorsHeaders(res);
res.end();
}
} else {
res.writeStatus("401 UNAUTHORIZED");
this.addCorsHeaders(res);
res.end();
}
} catch (error) {
console.error("getWorlds => ERROR", error);