angel_static 1.3.0+1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 86

static

Pub build status

Static server middleware for Angel.

Installation

In pubspec.yaml:

dependencies:
    angel_static: ^1.3.0-alpha

Usage

To serve files from a directory, you need to create a VirtualDirectory. Keep in mind that angel_static uses package:file instead of dart:io.

import 'package:angel_framework/angel_framework.dart';
import 'package:angel_static/angel_static.dart';
import 'package:file/local.dart';

main() async {
  var app = new Angel();
  var fs = const LocalFileSystem();

  // Normal static server
  var vDir = new VirtualDirectory(app, fs, source: new Directory('./public'));

  // Send Cache-Control, ETag, etc. as well
  var vDir = new CachingVirtualDirectory(app, fs, source: new Directory('./public'));

  // Mount the VirtualDirectory's request handler
  app.use(vDir.handleRequest);

  // Start your server!!!
  await app.startServer();
}

Push State

VirtualDirectory also exposes a pushState method that returns a request handler that serves the file at a given path as a fallback, unless the user is requesting that file. This can be very useful for SPA's.

// Create VirtualDirectory as well
var vDir = new CachingVirtualDirectory(...);

// Mount it
app.use(vDir.handleRequest);

// Fallback to index.html on 404
app.use(vDir.pushState('index.html'));

Options

The VirtualDirectory API accepts a few named parameters:

  • source: A Directory containing the files to be served. If left null, then Angel will serve either from web (in development) or build/web (in production), depending on your ANGEL_ENV.
  • indexFileNames: A List<String> of filenames that should be served as index pages. Default is ['index.html'].
  • publicPath: To serve index files, you need to specify the virtual path under which angel_static is serving your files. If you are not serving static files at the site root, please include this.
  • callback: Runs before sending a file to a client. Use this to set headers, etc. If it returns anything other than null or true, then the callback's result will be sent to the user, instead of the file contents.

1.3.0+1

  • Dart 2 fixes.
  • Enable optionally writing responses to the buffer instead of streaming.

1.3.0

  • pushState uses strict mode when accepts is passed.

1.3.0-alpha+2

  • Added an accepts option to pushState.
  • Added optional directory listings.

1.3.0-alpha+1

  • ETags once again only encode the first 50 bytes of files. Resolves #27.

1.3.0-alpha

  • Removed file transformers.
  • VirtualDirectory is no longer an AngelPlugin, and instead exposes a handleRequest middleware.
  • Added pushState to VirtualDirectory.

1.2.5

  • Fixed a bug where onlyInProduction was not properly adhered to.
  • Fixed another bug where Accept-Encoding was not properly adhered to.
  • Setting maxAge to null will now prevent a CachingVirtualDirectory from sending an Expires header.
  • Pre-built assets can now be mass-deleted with VirtualDirectory.cleanFromDisk(). Resolves #22.

1.2.4+1

Fixed a bug where Accept-Encoding was not properly adhered to.

1.2.4

Fixes https://github.com/angel-dart/angel/issues/44.

  • MIME types will now default to application/octet-stream.
  • When streamToIO is true, the body will only be sent gzipped if the request explicitly allows it.

1.2.3

Fixed #40 and #41, which dealt with paths being improperly served when using a publicPath.

example/main.dart

import 'package:angel_framework/angel_framework.dart';
import 'package:angel_static/angel_static.dart';
import 'package:file/local.dart';

main() async {
  var app = new Angel();
  var http = new AngelHttp(app);
  var fs = const LocalFileSystem();
  var vDir = new VirtualDirectory(
    app,
    fs,
    allowDirectoryListing: true,
    source: fs.directory(fs.currentDirectory),
  );
  app.use(vDir.handleRequest);

  var server = await http.startServer('127.0.0.1', 3000);
  print('Listening at http://${server.address.address}:${server.port}');
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  angel_static: ^1.3.0+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:angel_static/angel_static.dart';
  
Version Uploaded Documentation Archive
1.3.0+1 Jul 9, 2018 Go to the documentation of angel_static 1.3.0+1 Download angel_static 1.3.0+1 archive
1.3.0 Nov 28, 2017 Go to the documentation of angel_static 1.3.0 Download angel_static 1.3.0 archive
1.2.5 Aug 16, 2017 Go to the documentation of angel_static 1.2.5 Download angel_static 1.2.5 archive
1.2.4+1 Aug 15, 2017 Go to the documentation of angel_static 1.2.4+1 Download angel_static 1.2.4+1 archive
1.2.4 Jul 10, 2017 Go to the documentation of angel_static 1.2.4 Download angel_static 1.2.4 archive
1.2.3 Jun 20, 2017 Go to the documentation of angel_static 1.2.3 Download angel_static 1.2.3 archive
1.2.2+4 Jun 16, 2017 Go to the documentation of angel_static 1.2.2+4 Download angel_static 1.2.2+4 archive
1.2.2+3 Jun 16, 2017 Go to the documentation of angel_static 1.2.2+3 Download angel_static 1.2.2+3 archive
1.2.2+2 Jun 16, 2017 Go to the documentation of angel_static 1.2.2+2 Download angel_static 1.2.2+2 archive
1.2.2+1 Jun 16, 2017 Go to the documentation of angel_static 1.2.2+1 Download angel_static 1.2.2+1 archive

All 30 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
81
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
86
Learn more about scoring.

We analyzed this package on Aug 13, 2018, and provided a score, details, and suggestions below. Analysis was completed with status tool failures using:

  • Dart: 2.0.0
  • pana: 0.11.8

Platforms

Detected platforms: unsure

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Issues and suggestions

Fix dependencies in pubspec.yaml.

Running pub upgrade failed with the following output:

ERR: The current Dart SDK version is 2.0.0.
 
 Because angel_static depends on file >=0.1.0 <5.0.2 which requires SDK version <2.0.0-∞, version solving failed.

Fix platform conflicts.

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

The description is too short.

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <3.0.0