shelf_virtual_directory 1.0.0 copy "shelf_virtual_directory: ^1.0.0" to clipboard
shelf_virtual_directory: ^1.0.0 copied to clipboard

outdated

This package provides a virtual directory to serve static files from a directory.

example/example.dart

import 'dart:io';

import 'package:shelf/shelf.dart' show Cascade, Pipeline, logRequests;
import 'package:shelf/shelf_io.dart' as io show serve;

import 'package:shelf_virtual_directory/shelf_virtual_directory.dart'
    show ShelfVirtualDirectory;

void main(List<String> args) {
  // serving directory
  const folderToServe = 'web';
  final address = InternetAddress.anyIPv4;
  final port = int.parse(Platform.environment['PORT'] ?? '8082');

  // creates a [ShelfVirtualDirectory] instance and provides a [Router] instance.
  final virDirRouter = ShelfVirtualDirectory(folderToServe);

  // using [Pipeline] from shelf we can add a logging middleware.
  // we can use handler provided by [Router] instance.
  final staticFileHandler = const Pipeline()
      .addMiddleware(logRequests())
      .addHandler(virDirRouter.handler);

  // add the handler to [Cascade]
  io
      .serve(
        Cascade().add(staticFileHandler).handler,
        address,
        port,
      )
      .then(
        (server) =>
            print('Server is sunning at ${server.address}:${server.port}'),
      );
}
5
likes
0
pub points
60%
popularity

Publisher

verified publisherratakondalaarun.dev

This package provides a virtual directory to serve static files from a directory.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

mime, shelf, shelf_router

More

Packages that depend on shelf_virtual_directory