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 library dartiverse_search; | 5 library dartiverse_search; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 }); | 88 }); |
89 | 89 |
90 var buildPath = Platform.script.resolve('../build').toFilePath(); | 90 var buildPath = Platform.script.resolve('../build').toFilePath(); |
91 if (!new Directory(buildPath).existsSync()) { | 91 if (!new Directory(buildPath).existsSync()) { |
92 log.severe("The 'build/' directory was not found. Please run 'pub build'."); | 92 log.severe("The 'build/' directory was not found. Please run 'pub build'."); |
93 return; | 93 return; |
94 } | 94 } |
95 | 95 |
96 int port = 9223; // TODO use args from command line to set this | 96 int port = 9223; // TODO use args from command line to set this |
97 | 97 |
98 HttpServer.bind(InternetAddress.ANY_IP_V4, port).then((server) { | 98 HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, port).then((server) { |
99 log.info("Search server is running on " | 99 log.info("Search server is running on " |
100 "'http://${Platform.localHostname}:$port/'"); | 100 "'http://${server.address.address}:$port/'"); |
101 var router = new Router(server); | 101 var router = new Router(server); |
102 | 102 |
103 // The client will connect using a WebSocket. Upgrade requests to '/ws' and | 103 // The client will connect using a WebSocket. Upgrade requests to '/ws' and |
104 // forward them to 'handleWebSocket'. | 104 // forward them to 'handleWebSocket'. |
105 router.serve('/ws') | 105 router.serve('/ws') |
106 .transform(new WebSocketTransformer()) | 106 .transform(new WebSocketTransformer()) |
107 .listen(handleWebSocket); | 107 .listen(handleWebSocket); |
108 | 108 |
109 // Set up default handler. This will serve files from our 'build' directory. | 109 // Set up default handler. This will serve files from our 'build' directory. |
110 var virDir = new http_server.VirtualDirectory(buildPath); | 110 var virDir = new http_server.VirtualDirectory(buildPath); |
(...skipping 18 matching lines...) Expand all Loading... |
129 | 129 |
130 // Special handling of client.dart. Running 'pub build' generates | 130 // Special handling of client.dart. Running 'pub build' generates |
131 // JavaScript files but does not copy the Dart files, which are | 131 // JavaScript files but does not copy the Dart files, which are |
132 // needed for the Dartium browser. | 132 // needed for the Dartium browser. |
133 router.serve("/client.dart").listen((request) { | 133 router.serve("/client.dart").listen((request) { |
134 Uri clientScript = Platform.script.resolve("../web/client.dart"); | 134 Uri clientScript = Platform.script.resolve("../web/client.dart"); |
135 virDir.serveFile(new File(clientScript.toFilePath()), request); | 135 virDir.serveFile(new File(clientScript.toFilePath()), request); |
136 }); | 136 }); |
137 }); | 137 }); |
138 } | 138 } |
OLD | NEW |