decentralised sync engine
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: registration hof wrappers

serenity 8ae59a2c c5f251d7

+40
+40
src/lib/utils/registration.ts
··· 1 + import { getRegistrationState } from "@/lib/state"; 2 + import type { RouteHandler, WsRouteHandler } from "@/lib/types/routes"; 3 + import { newErrorResponse } from "@/lib/utils/http/responses"; 4 + 5 + export const wrapHttpRegistrationCheck = ( 6 + routeHandler: RouteHandler, 7 + ): RouteHandler => { 8 + const registrationState = getRegistrationState(); 9 + const wrappedFunction: RouteHandler = (req, rep) => { 10 + if (!registrationState.registered) { 11 + return newErrorResponse(503, { 12 + message: 13 + "Lattice has not been registered for use. Register it in the dashboard or make the record yourself using the bootstrapper if you're doing local development.", 14 + }); 15 + } 16 + 17 + return routeHandler(req, rep); 18 + }; 19 + 20 + return wrappedFunction; 21 + }; 22 + 23 + export function wrapWsRegistrationCheck( 24 + wsHandler: WsRouteHandler, 25 + ): WsRouteHandler { 26 + const registrationState = getRegistrationState(); 27 + const wrappedFunction: WsRouteHandler = (socket, request) => { 28 + if (!registrationState.registered) { 29 + socket.close( 30 + 1013, 31 + "Service unavailable: Lattice not yet registered", 32 + ); 33 + return; 34 + } 35 + 36 + wsHandler(socket, request); 37 + }; 38 + 39 + return wrappedFunction; 40 + }