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.
The static-file-handler can be used:
You can serve files from a directory by running the Dart script located into
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>
config.yaml file is available in the
For a description of all the possible parameters:
dart static_file_handler.dart --help
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
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
You can see an example in the
It is possible to add custom MIME types through a method call (
addMIMETypes(Map<String, String> types)), or by editing the config file.
Please file issues in the Issue Tracker
Special thanks to Anders Johnsen for the original code. Thanks to Adam Singer for his contribution.
Add this to your package's pubspec.yaml file:
dependencies: static_file_handler: ^0.2.2
You can install packages from the command line:
$ pub get
Alternatively, your editor might support
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
|0.2.2||Aug 17, 2014|
|0.2.1||Feb 11, 2014|
|0.2.0||Nov 9, 2013|
|0.1.3||Sep 24, 2013|
|0.1.2||Aug 31, 2013|
|0.1.1||Aug 31, 2013|
|0.1.0||Jun 20, 2013|
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.
Support Dart 2 in
The SDK constraint in
pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.
|Dart SDK||>=1.1.3 <2.0.0|