
dart-isoserver
dart-isoserver is a demonstration web server library that dynamically loads code from the filesystem to handle HTTP requests.
This demo serves a few purposes: 1. Show how to dynamically load Dart scripts into an isolate 1. Experiment with implementing an API proxy that communicates across Isolate ports. This will probably be a very common technique in Dart eventually. 1. Play with one way to build a 'hot-swapping' server. Changes to the dynamically loaded scripts are visible on browser refreshes.
The code is far from complete or production-ready, and very likely contains security holes, so please don't use this for anything serious. Besides, loading scripts from the file-system isn't that interesting aside from the hot-swapping-like behavior - running generated code or code loaded from a database will probably be more useful.
To try, run demo.dart and then point your web browser to either:
or
You can add your own Dart script and serve requests by creating a new IsoletServer
and using it much like a HttpServer
, except you don't call listen()
:
```
import('dart:io');
import('isolet.dart');
void main() {
new IsoletServer().defaultRequestHandler = (req, res) {
res.headers.set(HttpHeaders.CONTENT_TYPE, "text/html");
res.outputStream.writeString("Hello!");
res.outputStream.close();
};
}
To use the library to serve scripts, create a `IsoServerHandler` and add it's `requestHandler`
method to your `HttpServer`:
import("dart:io");
import("isoserver.dart");
void main() { HttpServer server = new HttpServer(); Path root = new Path(new Directory.current().path); IsoServerHandler handler = new IsoServerHandler(root); server.defaultRequestHandler = handler.handleRequest; server.listen("127.0.0.1", 8080); } ```
Project Information
The project was created on Jul 12, 2012.
- License: Apache License 2.0
- 12 stars
- git-based source control