blob: dbaa478df03d170cdbd1e9b9e5d0dc837593fe23 [file] [log] [blame]
library shelf_static;
import 'dart:io';
import 'package:path/path.dart' as p;
import 'package:shelf/shelf.dart';
// directory listing
// default document
// sym links
// mime type handling
Handler getHandler(String fileSystemPath) {
return (Request request) {
var rootDir = new Directory(fileSystemPath);
var rootPath = rootDir.resolveSymbolicLinksSync();
var segs = [rootPath]..addAll(request.pathSegments);
var requestedPath = p.joinAll(segs);
var file = new File(requestedPath);
return file.resolveSymbolicLinks().then((String resolvedPath) {
if(!p.isWithin(rootPath, resolvedPath)) {
throw 'Requested path ${request.pathInfo} resolved to $resolvedPath is not under $rootPath.';
}
return new Response.ok(file.openRead());
});
};
}