shelf_flutter_asset 0.0.4 copy "shelf_flutter_asset: ^0.0.4" to clipboard
shelf_flutter_asset: ^0.0.4 copied to clipboard

A simple handler for the Shelf ecosystem to serve files from Flutter assets.

shelf_flutter_asset #

build status codecov pub package package publisher

A simple handler for the Shelf ecosystem to serve files from Flutter assets.

Usage #

Bind as root handler:

import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_flutter_asset/shelf_flutter_asset.dart';

void main() {
  var assetHandler = createAssetHandler(defaultDocument: 'index.html');

  io.serve(assetHandler, 'localhost', 8080);
}

Bind with shelf_router:

import 'package:shelf_router/shelf_router.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;

void main() {
  var app = Router();
  final assetHandler = createAssetHandler();

  app.get('/hello', (Request request) {
    return Response.ok('hello-world');
  });

  app.get('/assets/<ignored|.*>', (Request request) {
    return assetHandler(request.change(path: 'assets'));
  });

  io.serve(app, 'localhost', 8080);
}

Bind with shelf_router and custom root path:

import 'package:shelf_router/shelf_router.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;

void main() {
  var app = Router();
  final assetHandler = createAssetHandler(rootPath: 'assets/html');

  app.get('/hello', (Request request) {
    return Response.ok('hello-world');
  });

  app.get('/assets/<ignored|.*>', (Request request) {
    return assetHandler(request.change(path: 'assets/html'));
  });

  io.serve(app, 'localhost', 8080);
}
5
likes
150
points
44
downloads

Publisher

verified publisherreight.io

Weekly Downloads

A simple handler for the Shelf ecosystem to serve files from Flutter assets.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, mime, path, shelf

More

Packages that depend on shelf_flutter_asset