HotFix Allow Origin header for CORS (#1566)
Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com>
This commit is contained in:
parent
f6b8677c2e
commit
75ba9ddae8
2 changed files with 4 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
||||||
import { HttpResponse } from "uWebSockets.js";
|
import { HttpResponse } from "uWebSockets.js";
|
||||||
|
import { FRONT_URL } from "../Enum/EnvironmentVariable";
|
||||||
|
|
||||||
export class BaseController {
|
export class BaseController {
|
||||||
protected addCorsHeaders(res: HttpResponse): void {
|
protected addCorsHeaders(res: HttpResponse): void {
|
||||||
|
@ -12,6 +13,7 @@ export class BaseController {
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
protected errorToResponse(e: any, res: HttpResponse): void {
|
protected errorToResponse(e: any, res: HttpResponse): void {
|
||||||
|
res.writeHeader("Access-Control-Allow-Origin", FRONT_URL);
|
||||||
if (e && e.message) {
|
if (e && e.message) {
|
||||||
let url = e?.config?.url;
|
let url = e?.config?.url;
|
||||||
if (url !== undefined) {
|
if (url !== undefined) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { HttpRequest, HttpResponse, TemplatedApp } from "uWebSockets.js";
|
||||||
import { BaseController } from "./BaseController";
|
import { BaseController } from "./BaseController";
|
||||||
import { parse } from "query-string";
|
import { parse } from "query-string";
|
||||||
import { adminApi } from "../Services/AdminApi";
|
import { adminApi } from "../Services/AdminApi";
|
||||||
import { ADMIN_API_URL, DISABLE_ANONYMOUS } from "../Enum/EnvironmentVariable";
|
import { ADMIN_API_URL, DISABLE_ANONYMOUS, FRONT_URL } from "../Enum/EnvironmentVariable";
|
||||||
import { GameRoomPolicyTypes } from "../Model/PusherRoom";
|
import { GameRoomPolicyTypes } from "../Model/PusherRoom";
|
||||||
import { isMapDetailsData, MapDetailsData } from "../Services/AdminApi/MapDetailsData";
|
import { isMapDetailsData, MapDetailsData } from "../Services/AdminApi/MapDetailsData";
|
||||||
import { socketManager } from "../Services/SocketManager";
|
import { socketManager } from "../Services/SocketManager";
|
||||||
|
@ -20,7 +20,6 @@ export class MapController extends BaseController {
|
||||||
getMapUrl() {
|
getMapUrl() {
|
||||||
this.App.options("/map", (res: HttpResponse, req: HttpRequest) => {
|
this.App.options("/map", (res: HttpResponse, req: HttpRequest) => {
|
||||||
this.addCorsHeaders(res);
|
this.addCorsHeaders(res);
|
||||||
|
|
||||||
res.end();
|
res.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -88,6 +87,7 @@ export class MapController extends BaseController {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// The token was not good, redirect user on login page
|
// The token was not good, redirect user on login page
|
||||||
res.writeStatus("500");
|
res.writeStatus("500");
|
||||||
|
res.writeHeader("Access-Control-Allow-Origin", FRONT_URL);
|
||||||
res.end("Token decrypted error");
|
res.end("Token decrypted error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue