Refactoring Woka management (#1810)
* Wrap websockets with HyperExpress * Add endpoints on pusher to resolve wokas * getting textures urls from pusher * Adding OpenAPI documentation for the pusher. The pusher now exposes a "/openapi" endpoint and a "/swagger-ui/" endpoint. * revert FRONT_URL * playerTextures metadata is being loaded via Phaser.Loader * fetch textures every time character or customize scene is open * Heavy changes: refactoring the pusher to always send the textures (and the front to accept them) * Sending character layer details to admin * Cleaning commented code * Fixing regex * Fix woka endpoints on pusher * Change error wording on pusher * Working on integration of the woka-list with the new admin endpoint. * Switching from "name" to "id" in texture object + using zod for woka/list validation * Add position on default woka data * Remove async on pusher option method * Fix woka list url * add options for /register * Fxiing loading the Woka list * Actually returning something in logout-callback * Copying messages to back too * remove customize button if no body parts are available (#1952) * remove customize button if no body parts are available * remove unused position field from PlayerTexturesCollection interface * removed unused label field * fix LocalUser test * little PlayerTextures class refactor * Fixing linting * Fixing missing Openapi packages in prod * Fixing back build Co-authored-by: Hanusiak Piotr <piotr@ltmp.co> Co-authored-by: David Négrier <d.negrier@thecodingmachine.com> * Add returns on pusher endpoints Co-authored-by: Alexis Faizeau <a.faizeau@workadventu.re> Co-authored-by: Hanusiak Piotr <piotr@ltmp.co> Co-authored-by: Piotr Hanusiak <wacneg@gmail.com>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import Request from "hyper-express/types/components/http/Request";
|
||||
import Response from "hyper-express/types/components/http/Response";
|
||||
import { MiddlewareNext, MiddlewarePromise } from "hyper-express/types/components/router/Router";
|
||||
import { ADMIN_API_TOKEN } from "../Enum/EnvironmentVariable";
|
||||
|
||||
export function adminToken(req: Request, res: Response, next?: MiddlewareNext): MiddlewarePromise {
|
||||
const token = req.header("admin-token");
|
||||
|
||||
if (ADMIN_API_TOKEN === "") {
|
||||
res.status(401).end("No token configured!");
|
||||
return;
|
||||
}
|
||||
if (token !== ADMIN_API_TOKEN) {
|
||||
console.error("Admin access refused for token: " + token);
|
||||
res.status(401).end("Incorrect token");
|
||||
return;
|
||||
}
|
||||
|
||||
if (next) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import Request from "hyper-express/types/components/http/Request";
|
||||
import Response from "hyper-express/types/components/http/Response";
|
||||
import { MiddlewareNext, MiddlewarePromise } from "hyper-express/types/components/router/Router";
|
||||
import { FRONT_URL } from "../Enum/EnvironmentVariable";
|
||||
|
||||
export function cors(req: Request, res: Response, next?: MiddlewareNext): MiddlewarePromise {
|
||||
res.setHeader(
|
||||
"access-control-allow-headers",
|
||||
"Origin, X-Requested-With, Content-Type, Accept, Authorization, Pragma, Cache-Control"
|
||||
);
|
||||
res.setHeader("access-control-allow-methods", "GET, POST, OPTIONS, PUT, PATCH, DELETE");
|
||||
res.setHeader("access-control-allow-origin", FRONT_URL);
|
||||
res.setHeader("access-control-allow-credentials", "true");
|
||||
|
||||
if (next) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import Request from "hyper-express/types/components/http/Request";
|
||||
import Response from "hyper-express/types/components/http/Response";
|
||||
import { MiddlewareNext, MiddlewarePromise } from "hyper-express/types/components/router/Router";
|
||||
|
||||
export function hasToken(req: Request, res: Response, next?: MiddlewareNext): MiddlewarePromise {
|
||||
const authorizationHeader = req.header("Authorization");
|
||||
|
||||
if (!authorizationHeader) {
|
||||
res.status(401).send("Undefined authorization header");
|
||||
return;
|
||||
}
|
||||
|
||||
if (next) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user