angel_static 1.3.0

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

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

  • 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 fs = const LocalFileSystem();
  var vDir = new VirtualDirectory(
    app,
    fs,
    allowDirectoryListing: true,
    source: fs.directory(fs.currentDirectory),
  );
  app.use(vDir.handleRequest);

  var server = await app.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"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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 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
1.2.2 Jun 16, 2017 Go to the documentation of angel_static 1.2.2 Download angel_static 1.2.2 archive

All 29 versions...

Analysis

We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3

Scores

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

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:angel_static/angel_static.dart.

Suggestions

  • 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.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 4 hints.

    Strong-mode analysis of lib/src/cache.dart gave the following hint:

    line: 3 col: 8
    Unused import: 'dart:typed_data'.

    Run dartfmt to format lib/src/virtual_directory.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0
angel_framework ^1.1.0-alpha 1.1.4+3
file ^2.0.0 2.3.7 5.0.1
intl >=0.0.0 <1.0.0 0.15.6
mime ^0.9.3 0.9.6+1
path ^1.4.2 1.6.1
Transitive dependencies
angel_http_exception 1.0.0
angel_model 1.0.0
angel_route 2.0.6
async 2.0.7
body_parser 1.1.0
charcode 1.1.1
code_buffer 1.0.0
collection 1.14.10
combinator 1.0.0
container 0.1.2
dart2_constant 1.0.1+dart2
http_parser 3.1.2
http_server 0.9.7
json_god 2.0.0-beta+1
logging 0.11.3+1
matcher 0.12.3
merge_map 1.0.0
meta 1.1.5
pool 1.3.5
quiver_hashcode 1.0.0
random_string 0.0.1
source_span 1.4.0
stack_trace 1.9.2
string_scanner 1.0.2
tuple 1.0.1
typed_data 1.1.5
Dev dependencies
angel_test ^1.1.0-alpha
http ^0.11.3
mustache4dart ^1.1.0
test ^0.12.13