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.

shelf_virtual_directory #

This package provides Handler, Router and Cascade to serve static files from the dart shelf server and can work with websockets.

Provider UseCase
Handler Can be used to serve as a handler for Pipeline or for Cascade
Router Can be used to mount as a subroute
Cascade Can be used directly serve from shelf server

Setup #

  1. Add to pubspec.yaml file

    dependencies:
        shelf_virtual_directory: latest_version
    
  2. Get dependencies

    pub get
    
  3. Import

    import 'package:shelf_virtual_directory/shelf_virtual_directory.dart';
    
  4. Create a instance of ShelfVirtualDirectory with a directory ../web

    final virtualDir = ShelfVirtualDirectory('../web');
    

Handling different cases #

  • Using as a Handler

    final virDirHandler = ShelfVirtualDirectory('../web').handler;
    
    final staticFileHandler = const Pipeline()
        .addMiddleware(logRequests())
        .addHandler(virDirHandler);//used as a handler
    
    io.serve(Cascade().add(staticFileHandler).handler,address,port).then((server){
         print('Server is sunning at ${server.address}:${server.port}'),
    });
    
  • Using as a Router

    final router = Router('/',ShelfVirtualDirectory('../web').router); // localhost:8080/
    //or
    final router = Router('/home/',ShelfVirtualDirectory('../web').router); //localhost:8080/home/
    
  • Using as a Cascade

    import 'package:shelf/shelf_io.dart' as io show serve;
    
    final cascade = ShelfVirtualDirectory('web').cascade;
    io.serve(cascade,'localhost',8080).then((server){
      print('Server is sunning at ${server.address}:${server.port}'),
    })
    

Contrubitions #

All contrubitions are welcomed.

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