registerAssetsFilesPath method

dynamic registerAssetsFilesPath({
  1. String path = '*',
  2. String assetsPrefix = "",
  3. ResponseProcessor? responseProcessor,
  4. Function? errorFunction,
})

Implementation

registerAssetsFilesPath({String path = '*',String assetsPrefix="",ResponseProcessor? responseProcessor,Function? errorFunction}) {
  jaguarMux.Route route = jaguarMux.Route.get(path, (context) async {
    dynamic body = "";
    String? mimeType = 'text/html';
    try {
      String routePath = context.path;
      if (routePath.startsWith("/")) {
        routePath = routePath.substring(1);
      }
      _log("Loading Asset File for path " + routePath + "");
      body = (await rootBundle.load('$assetsPrefix$routePath')).buffer.asUint8List();
      String extension=Simplify.getFileExtensionFromPath(routePath);
      _log("Found Asset $routePath : Extension : $extension : Mime : $mimeType");
      mimeType = MimeList.fromExtension[extension];
      context.response = ByteResponse(body: body, mimeType: mimeType);
      // context.response = ByteResponse(body: body, mimeType: mimeType);
    } catch (ex,stack) {
      _log(ex);
      _log(stack);
      context.response = Response(statusCode: HttpStatus.notFound);
      if (errorFunction != null) {
        dynamic errorResponse =
        errorFunction(Simplify.getExceptionMessage(ex,stack: stack));
        if (errorResponse != null) {
          context.response = Response.html(errorResponse);
        }
      }
    }
  }, responseProcessor: responseProcessor);
  routes.add(route);
}