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 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 file = new File('$baseDir$path.txt'); | 50 file = new File('$baseDir$path.txt'); |
51 } else { | 51 } else { |
52 file = new File('$baseDir$path'); | 52 file = new File('$baseDir$path'); |
53 } | 53 } |
54 | 54 |
55 file.readAsBytes().then((data) { | 55 file.readAsBytes().then((data) { |
56 response.statusCode = 200; | 56 response.statusCode = 200; |
57 response.contentLength = data.length; | 57 response.contentLength = data.length; |
58 response.add(data); | 58 response.add(data); |
59 response.close(); | 59 response.close(); |
60 }).catchError((e) { | 60 }).catchError((e, trace) { |
61 print(getAttachedStackTrace(e)); | 61 print(trace); |
62 response.statusCode = 404; | 62 response.statusCode = 404; |
63 response.contentLength = 0; | 63 response.contentLength = 0; |
64 response.close(); | 64 response.close(); |
65 }); | 65 }); |
66 } catch (e) { | 66 } catch (e) { |
67 print(e); | 67 print(e); |
68 response.statusCode = 500; | 68 response.statusCode = 500; |
69 response.close(); | 69 response.close(); |
70 return; | 70 return; |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
OLD | NEW |