Adding /map endpoint to Node API
This commit is contained in:
parent
9a04836215
commit
ac86914d82
2 changed files with 52 additions and 11 deletions
|
@ -2,6 +2,8 @@ import {OK} from "http-status-codes";
|
|||
import {URL_ROOM_STARTED} from "../Enum/EnvironmentVariable";
|
||||
import {HttpRequest, HttpResponse, TemplatedApp} from "uWebSockets.js";
|
||||
import {BaseController} from "./BaseController";
|
||||
import {parse} from "query-string";
|
||||
import {adminApi} from "../Services/AdminApi";
|
||||
|
||||
//todo: delete this
|
||||
export class MapController extends BaseController{
|
||||
|
@ -9,26 +11,42 @@ export class MapController extends BaseController{
|
|||
constructor(private App : TemplatedApp) {
|
||||
super();
|
||||
this.App = App;
|
||||
this.getStartMap();
|
||||
this.getMapUrl();
|
||||
}
|
||||
|
||||
|
||||
// Returns a map mapping map name to file name of the map
|
||||
getStartMap() {
|
||||
this.App.options("/start-map", (res: HttpResponse, req: HttpRequest) => {
|
||||
getMapUrl() {
|
||||
this.App.options("/map", (res: HttpResponse, req: HttpRequest) => {
|
||||
this.addCorsHeaders(res);
|
||||
|
||||
res.end();
|
||||
});
|
||||
|
||||
this.App.get("/start-map", (res: HttpResponse, req: HttpRequest) => {
|
||||
this.App.get("/map", (res: HttpResponse, req: HttpRequest) => {
|
||||
this.addCorsHeaders(res);
|
||||
|
||||
const url = req.getHeader('host').replace('api.', 'maps.') + URL_ROOM_STARTED;
|
||||
res.writeStatus("200 OK").end(JSON.stringify({
|
||||
mapUrlStart: url,
|
||||
startInstance: "global"
|
||||
}));
|
||||
const query = parse(req.getQuery());
|
||||
|
||||
if (typeof query.organizationSlug !== 'string') {
|
||||
console.error('Expected organizationSlug parameter');
|
||||
res.writeStatus("400 Bad request").end("Expected organizationSlug parameter");
|
||||
}
|
||||
if (typeof query.worldSlug !== 'string') {
|
||||
console.error('Expected worldSlug parameter');
|
||||
res.writeStatus("400 Bad request").end("Expected worldSlug parameter");
|
||||
}
|
||||
if (typeof query.roomSlug !== 'string' && query.roomSlug !== undefined) {
|
||||
console.error('Expected only one roomSlug parameter');
|
||||
res.writeStatus("400 Bad request").end("Expected only one roomSlug parameter");
|
||||
}
|
||||
|
||||
(async () => {
|
||||
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));
|
||||
})();
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue