StaticHandler.file constructor

StaticHandler.file(
  1. File file, {
  2. MimeTypeResolver? mimeResolver,
  3. required CacheControlFactory cacheControl,
})

Creates a StaticHandler for serving a single File.

Note: Cache busting is not supported for single file handlers as the file is directly specified and URL-to-file mapping is handled by the router. For cache-busted URLs with single files, use query parameters or router path parameters instead.

Implementation

factory StaticHandler.file(
  final File file, {
  final MimeTypeResolver? mimeResolver,
  required final CacheControlFactory cacheControl,
}) {
  if (!file.existsSync()) {
    throw ArgumentError('File "${file.path}" does not exist');
  }
  return StaticHandler._(
    file,
    mimeResolver: mimeResolver,
    cacheControl: cacheControl,
  );
}