forked from firka/flutter
merge to master
This commit is contained in:
@@ -8,18 +8,33 @@ import 'package:args/args.dart';
|
||||
import 'package:shelf_static/shelf_static.dart';
|
||||
import 'package:shelf/shelf_io.dart' as io;
|
||||
import 'package:shelf/shelf.dart';
|
||||
import 'package:shelf_route/shelf_route.dart' as shelf_route;
|
||||
|
||||
void printUsage(parser) {
|
||||
print('Usage: sky_server [-v] PORT');
|
||||
print(parser.usage);
|
||||
}
|
||||
|
||||
void addRoute(var router, String route, String path) {
|
||||
router.add(
|
||||
route,
|
||||
['GET'],
|
||||
createStaticHandler(
|
||||
path,
|
||||
serveFilesOutsidePath: true,
|
||||
listDirectories: true
|
||||
), exactMatch: false
|
||||
);
|
||||
}
|
||||
|
||||
main(List<String> argv) async {
|
||||
ArgParser parser = new ArgParser();
|
||||
parser.addFlag('help', abbr: 'h', negatable: false,
|
||||
help: 'Display this help message.');
|
||||
parser.addFlag('verbose', abbr: 'v', negatable: false,
|
||||
help: 'Log requests to stdout.');
|
||||
parser.addOption('route', allowMultiple: true, splitCommas: false,
|
||||
help: 'Adds a virtual directory to the root.');
|
||||
|
||||
ArgResults args = parser.parse(argv);
|
||||
|
||||
@@ -36,8 +51,18 @@ main(List<String> argv) async {
|
||||
return;
|
||||
}
|
||||
|
||||
Handler handler = createStaticHandler(Directory.current.path,
|
||||
serveFilesOutsidePath: true, listDirectories: true);
|
||||
var router = shelf_route.router();
|
||||
|
||||
if (args['route'] != null) {
|
||||
for (String arg in args['route']) {
|
||||
List<String> parsedArgs = arg.split(',');
|
||||
addRoute(router, parsedArgs[0], parsedArgs[1]);
|
||||
}
|
||||
}
|
||||
|
||||
addRoute(router, '/', Directory.current.path);
|
||||
|
||||
var handler = router.handler;
|
||||
|
||||
if (args['verbose'])
|
||||
handler = const Pipeline().addMiddleware(logRequests()).addHandler(handler);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: sky_tools
|
||||
version: 0.0.6
|
||||
version: 0.0.8
|
||||
description: Tools for building Sky applications
|
||||
homepage: https://github.com/domokit/sky_tools
|
||||
author: Chromium Authors <sky-dev@googlegroups.com>
|
||||
@@ -11,6 +11,7 @@ dependencies:
|
||||
args: ^0.13.0
|
||||
path: ^1.3.0
|
||||
shelf: ^0.6.2
|
||||
shelf_route: ^0.13.4
|
||||
shelf_static: ^0.2.3
|
||||
|
||||
dev_dependencies:
|
||||
|
||||
Reference in New Issue
Block a user