Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1752)

Unified Diff: mojo/public/dart/third_party/shelf_static/example/example_server.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/dart/third_party/shelf_static/example/example_server.dart
diff --git a/mojo/public/dart/third_party/shelf_static/example/example_server.dart b/mojo/public/dart/third_party/shelf_static/example/example_server.dart
new file mode 100644
index 0000000000000000000000000000000000000000..1233eef548cf791bc9d4dbc3e45d213ae3e5a80c
--- /dev/null
+++ b/mojo/public/dart/third_party/shelf_static/example/example_server.dart
@@ -0,0 +1,65 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library shelf_static.example;
+
+import 'dart:io';
+import 'package:args/args.dart';
+import 'package:shelf/shelf.dart' as shelf;
+import 'package:shelf/shelf_io.dart' as io;
+import 'package:shelf_static/shelf_static.dart';
+
+void main(List<String> args) {
+ var parser = _getParser();
+
+ int port;
+ bool logging;
+ bool listDirectories;
+
+ try {
+ var result = parser.parse(args);
+ port = int.parse(result['port']);
+ logging = result['logging'];
+ listDirectories = result['list-directories'];
+ } on FormatException catch (e) {
+ stderr.writeln(e.message);
+ stderr.writeln(parser.usage);
+ // http://linux.die.net/include/sysexits.h
+ // #define EX_USAGE 64 /* command line usage error */
+ exit(64);
+ }
+
+ if (!FileSystemEntity.isFileSync('example/example_server.dart')) {
+ throw new StateError('Server expects to be started the '
+ 'root of the project.');
+ }
+ var pipeline = const shelf.Pipeline();
+
+ if (logging) {
+ pipeline = pipeline.addMiddleware(shelf.logRequests());
+ }
+
+ var defaultDoc = _defaultDoc;
+ if (listDirectories) {
+ defaultDoc = null;
+ }
+
+ var handler = pipeline.addHandler(createStaticHandler('example/files',
+ defaultDocument: defaultDoc, listDirectories: listDirectories));
+
+ io.serve(handler, 'localhost', port).then((server) {
+ print('Serving at http://${server.address.host}:${server.port}');
+ });
+}
+
+ArgParser _getParser() => new ArgParser()
+ ..addFlag('logging', abbr: 'l', defaultsTo: true, negatable: true)
+ ..addOption('port', abbr: 'p', defaultsTo: '8080')
+ ..addFlag('list-directories',
+ abbr: 'f',
+ defaultsTo: false,
+ negatable: false,
+ help: 'List the files in the source directory instead of servering the default document - "$_defaultDoc".');
+
+const _defaultDoc = 'index.html';

Powered by Google App Engine
This is Rietveld 408576698