ensureInitialized method

  1. @override
void ensureInitialized()
override

Implementation

@override
void ensureInitialized() {
  ServerUniverseEdgeLib.ensureInitialized();
  if (serverUniversePlatformType == ServerUniversePlatformType.supabase) {
    server_universeDartSupabaseFetchHandler = allowInterop((interop.Request request) {
      return futureToPromise(Future(() async {
        Request requestDart = requestFromJsObject(request);
        if (serverUniverseLogType == ServerUniverseLogType.info || serverUniverseLogType == ServerUniverseLogType.all) {
          print("[REQUEST]: ${DateTime.now().toString()} ${requestDart.path}");
        }
        try {
          ServerUniverseFunction? server_universeDartFunction = await getServerUniverseFunctionApiByRequest(request: requestDart);
          if (server_universeDartFunction != null) {
            Response response = await server_universeDartFunction.onRequest(requestDart, ServerUniverseFunctionResponse());
            return response.delegate;
          }
          Response response = await onNotFound(requestDart, ServerUniverseFunctionResponse());
          return response.delegate;
        } catch (e, stack) {
          if (serverUniverseLogType == ServerUniverseLogType.error || serverUniverseLogType == ServerUniverseLogType.all) {
            print("""
---
---
[ERROR]: ${DateTime.now().toString()}
${e}
${stack}
---
---
"""
                .trim());
          }
          try {
            Response response = await onError(requestDart, ServerUniverseFunctionResponse(), e, stack);
            return response.delegate;
          } catch (e) {
            return ServerUniverseFunctionResponse().status(500).send("crash").delegate;
          }
        }
      }));
    });
  }
}