OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// Runs a HTTP server on localhost that mimics the behavoir of pub.dartlang.org | 5 /// Runs a HTTP server on localhost that mimics the behavoir of pub.dartlang.org |
6 /// and serves files on pub requests. Files to be stored are on disk in the file | 6 /// and serves files on pub requests. Files to be stored are on disk in the file |
7 /// system. | 7 /// system. |
8 /// | 8 /// |
9 /// The port for the server and the base directory of the data to be served | 9 /// The port for the server and the base directory of the data to be served |
10 /// should be passed in as arguments | 10 /// should be passed in as arguments |
11 | 11 |
12 library pub_package_server; | 12 library pub_package_server; |
13 | 13 |
14 import 'dart:async'; | 14 import 'dart:async'; |
15 import 'dart:io'; | 15 import 'dart:io'; |
16 | 16 |
17 const LOG_REQUESTS = true; | 17 const LOG_REQUESTS = true; |
18 | 18 |
19 String baseDir; | 19 String baseDir; |
20 | 20 |
21 main() { | 21 main(List<String> options) { |
22 int port; | 22 int port; |
23 var options = new Options().arguments; | |
24 if (options.length != 1) { | 23 if (options.length != 1) { |
25 print('Insufficient arguments \npub_package_server serverDataLocation'); | 24 print('Insufficient arguments \npub_package_server serverDataLocation'); |
26 exit(64); | 25 exit(64); |
27 } | 26 } |
28 | 27 |
29 baseDir = options.first; | 28 baseDir = options.first; |
30 | 29 |
31 HttpServer.bind("localhost", 0).then((server) { | 30 HttpServer.bind("localhost", 0).then((server) { |
32 port = server.port; | 31 port = server.port; |
33 server.listen(requestReceivedHandler); | 32 server.listen(requestReceivedHandler); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 response.close(); | 64 response.close(); |
66 }); | 65 }); |
67 } catch (e) { | 66 } catch (e) { |
68 print(e); | 67 print(e); |
69 response.statusCode = 500; | 68 response.statusCode = 500; |
70 response.close(); | 69 response.close(); |
71 return; | 70 return; |
72 } | 71 } |
73 } | 72 } |
74 | 73 |
OLD | NEW |