Adding a /map route and removing /start-map

This commit is contained in:
David Négrier 2020-10-13 15:29:08 +02:00
parent ac86914d82
commit 94538bfaf4
2 changed files with 13 additions and 4 deletions

View File

@ -26,6 +26,10 @@ export class MapController extends BaseController{
this.App.get("/map", (res: HttpResponse, req: HttpRequest) => { this.App.get("/map", (res: HttpResponse, req: HttpRequest) => {
this.addCorsHeaders(res); this.addCorsHeaders(res);
res.onAborted(() => {
console.warn('/map request was aborted');
})
const query = parse(req.getQuery()); const query = parse(req.getQuery());
if (typeof query.organizationSlug !== 'string') { if (typeof query.organizationSlug !== 'string') {
@ -42,9 +46,14 @@ export class MapController extends BaseController{
} }
(async () => { (async () => {
try {
const mapDetails = await adminApi.fetchMapDetails(query.organizationSlug as string, query.worldSlug as string, query.roomSlug as string|undefined); const mapDetails = await adminApi.fetchMapDetails(query.organizationSlug as string, query.worldSlug as string, query.roomSlug as string|undefined);
res.writeStatus("200 OK").end(JSON.stringify(mapDetails)); res.writeStatus("200 OK").end(JSON.stringify(mapDetails));
} catch (e) {
console.error(e);
res.writeStatus("500 Internal Server Error").end("An error occurred");
}
})(); })();
}); });

View File

@ -17,13 +17,13 @@ class AdminApi {
return Promise.reject('No admin backoffice set!'); return Promise.reject('No admin backoffice set!');
} }
const params: { organizationSlug: string, worldSlug: string, mapSlug?: string } = { const params: { organizationSlug: string, worldSlug: string, roomSlug?: string } = {
organizationSlug, organizationSlug,
worldSlug worldSlug
}; };
if (roomSlug) { if (roomSlug) {
params.mapSlug = roomSlug; params.roomSlug = roomSlug;
} }
const res = await Axios.get(ADMIN_API_URL+'/api/map', const res = await Axios.get(ADMIN_API_URL+'/api/map',