static_file_handler 0.2.2

  • README.md
  • Installing
  • Versions
  • 10

static-file-handler

A static file Web server written in Dart. It can be used as a stand-alone command line tool or imported as a package in a Dart application.

Build Status

Usage

The static-file-handler can be used:

  • From the command line to serve files from a directory
  • To serve static files while your server side app takes care of all the dynamic requests
  • To spawn a Web server and serve static content from your app

Serve a directory from the command line

You can serve files from a directory by running the Dart script located into bin:

cd static_file_handler/bin
dart static_file_handler.dart -r <root-path> -p <port>

Optionally, you can specify a configuration file in the command line parameters.

dart static_file_handler.dart -c <config-file>

A sample config.yaml file is available in the bin folder.

For a description of all the possible parameters:

dart static_file_handler.dart --help

Serve static files from your server app

Add the package to your pubspec.yaml file:

dependencies:
  static_file_handler: any

Create an instance of the static file handler using the named constructor serveFolder(String directory), then call handleRequest(HttpRequest request) to serve your files. In this way your server application can handle all the dynamic requests, and you won't have to take care of the static files.

StaticFileHandler fileHandler = new StaticFileHandler.serveFolder("/path/to/folder");

fileHandler.handleRequest(httpRequest);

You can see an example that uses the route package to feed the static file handler only with non-dynamic requests in the example/handle_request folder.

Spawn a Web server and serve static content from your app

If you just want to serve static files from your application, you can do as follows:

var fileHandler = new StaticFileHandler(path, port: port);
  
fileHandler.start();

When you are done you can stop the Web server using fileHandler.stop().

You can see an example in the example/serve_folder folder.

Adding custom MIME types

It is possible to add custom MIME types through a method call (addMIMETypes(Map<String, String> types)), or by editing the config file.

Issues

Please file issues in the Issue Tracker

Acknowledgements

Special thanks to Anders Johnsen for the original code. Thanks to Adam Singer for his contribution.

Use this package as a library

1. Depend on it

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


dependencies:
  static_file_handler: "^0.2.2"

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:static_file_handler/static_file_handler.dart';
  
Version Uploaded Documentation Archive
0.2.2 Aug 17, 2014 Go to the documentation of static_file_handler 0.2.2 Download static_file_handler 0.2.2 archive
0.2.1 Feb 11, 2014 Go to the documentation of static_file_handler 0.2.1 Download static_file_handler 0.2.1 archive
0.2.0 Nov 9, 2013 Go to the documentation of static_file_handler 0.2.0 Download static_file_handler 0.2.0 archive
0.1.3 Sep 24, 2013 Go to the documentation of static_file_handler 0.1.3 Download static_file_handler 0.1.3 archive
0.1.2 Aug 31, 2013 Go to the documentation of static_file_handler 0.1.2 Download static_file_handler 0.1.2 archive
0.1.1 Aug 31, 2013 Go to the documentation of static_file_handler 0.1.1 Download static_file_handler 0.1.1 archive
0.1.0 Jun 20, 2013 Go to the documentation of static_file_handler 0.1.0 Download static_file_handler 0.1.0 archive

Analysis

We analyzed this package on Jul 17, 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]
0 / 100
Health:
Code health derived from static analysis. [more]
33 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0 / 100
Overall score:
Weighted score of the above. [more]
10
Learn more about scoring.

Platforms

Detected platforms: unsure

Error(s) prevent platform classification:

Error(s) in lib/static_file_handler.dart: Target of URI doesn't exist: 'package:path/path.dart'.

Suggestions

  • Fix platform conflicts.

    Error(s) prevent platform classification:

    Error(s) in lib/static_file_handler.dart: Target of URI doesn't exist: 'package:path/path.dart'.

  • Running dartdoc failed.

    Make sure dartdoc runs without any issues.

  • Maintain CHANGELOG.md.

    Changelog entries help clients to follow the progress in your code.

  • Package is too old.

    The package was released more than two years ago.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 3 errors 14 hints.

    Make sure that the imported libraries are not in conflict. Error(s) in lib/static_file_handler.dart: Target of URI doesn't exist: 'package:path/path.dart'.

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

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use static_file_handler.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.1.3 <2.0.0
args >=0.10.0 <0.11.0 0.10.0+2 1.4.3
yaml >=0.9.0 <0.10.0 0.9.0+2 2.1.14
Transitive dependencies
collection 0.9.4 1.14.10
Dev dependencies
path >=1.0.0 <2.0.0
route >=0.4.6
unittest >=0.9.0 <0.10.0