staticFile method

Route staticFile(
  1. String path,
  2. dynamic file, {
  3. Map<String, String>? pathRegEx,
  4. int statusCode = 200,
  5. String? mimeType,
  6. String? charset = kDefaultCharset,
  7. ResponseProcessor? responseProcessor,
  8. Iterable<String? Function(File)>? mimeTypeDetectors,
})

Serves requests at path with content of file

Example: final server = Jaguar(); server.staticFile('/hello', p.join('static', 'hello.txt')); await server.serve();

Implementation

Route staticFile(String path, file,
    {Map<String, String>? pathRegEx,
    int statusCode = 200,
    String? mimeType,
    String? charset = kDefaultCharset,
    ResponseProcessor? responseProcessor,
    Iterable<String? Function(File)>? mimeTypeDetectors}) {
  if (file is String) file = File(file);

  final File f = file;
  return this.get(
      path,
      (_) async => StreamResponse(
          body: f.openRead(),
          mimeType: MimeTypes.ofFile(f, detectors: mimeTypeDetectors)),
      pathRegEx: pathRegEx,
      statusCode: statusCode,
      mimeType: mimeType,
      charset: charset,
      responseProcessor: responseProcessor);
}