| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'dart:io'; |
| 6 |
| 7 import 'package:args/args.dart'; |
| 8 import 'package:logging/logging.dart'; |
| 9 import 'package:shelf/shelf_io.dart' as shelf_io; |
| 10 import 'package:http/http.dart' as http; |
| 11 import 'package:pub_server/shelf_pubserver.dart'; |
| 12 |
| 13 import 'src/examples/file_repository.dart'; |
| 14 import 'src/examples/http_proxy_repository.dart'; |
| 15 import 'src/examples/cow_repository.dart'; |
| 16 |
| 17 final Uri PubDartLangOrg = Uri.parse('https://pub.dartlang.org'); |
| 18 |
| 19 |
| 20 main(List<String> args) { |
| 21 var parser = argsParser(); |
| 22 var results = parser.parse(args); |
| 23 |
| 24 var directory = results['directory']; |
| 25 var host = results['host']; |
| 26 var port = int.parse(results['port']); |
| 27 |
| 28 if (results.rest.length > 0) { |
| 29 print('Got unexpected arguments: "${results.rest.join(' ')}".\n\nUsage:\n'); |
| 30 print(parser.usage); |
| 31 exit(1); |
| 32 } |
| 33 |
| 34 setupLogger(); |
| 35 runPubServer(directory, host, port); |
| 36 } |
| 37 |
| 38 runPubServer(String baseDir, String host, int port) { |
| 39 var client = new http.Client(); |
| 40 |
| 41 var local = new FileRepository(baseDir); |
| 42 var remote = new HttpProxyRepository(client, PubDartLangOrg); |
| 43 var cow = new CopyAndWriteRepository(local, remote); |
| 44 |
| 45 var server = new ShelfPubServer(cow); |
| 46 print('Listening on http://$host:$port\n' |
| 47 '\n' |
| 48 'To make the pub client use this repository configure your shell via:\n' |
| 49 '\n' |
| 50 ' \$ export PUB_HOSTED_URL=http://$host:$port\n' |
| 51 '\n'); |
| 52 return shelf_io.serve(server.requestHandler, host, port); |
| 53 } |
| 54 |
| 55 ArgParser argsParser() { |
| 56 var parser = new ArgParser(); |
| 57 |
| 58 parser.addOption('directory', |
| 59 abbr: 'd', |
| 60 defaultsTo: 'pub_server-repository-data'); |
| 61 |
| 62 parser.addOption('host', |
| 63 abbr: 'h', |
| 64 defaultsTo: 'localhost'); |
| 65 |
| 66 parser.addOption('port', |
| 67 abbr: 'p', |
| 68 defaultsTo: '8080'); |
| 69 return parser; |
| 70 } |
| 71 |
| 72 void setupLogger() { |
| 73 Logger.root.onRecord.listen((LogRecord record) { |
| 74 var head = '${record.time} ${record.level} ${record.loggerName}'; |
| 75 var tail = record.stackTrace != null ? '\n${record.stackTrace}' : ''; |
| 76 print('$head ${record.message} $tail'); |
| 77 }); |
| 78 } |
| OLD | NEW |