| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 85 } |
| 86 | 86 |
| 87 | 87 |
| 88 void main() { | 88 void main() { |
| 89 // Set up logger. | 89 // Set up logger. |
| 90 Logger.root.level = Level.ALL; | 90 Logger.root.level = Level.ALL; |
| 91 Logger.root.onRecord.listen((LogRecord rec) { | 91 Logger.root.onRecord.listen((LogRecord rec) { |
| 92 print('${rec.level.name}: ${rec.time}: ${rec.message}'); | 92 print('${rec.level.name}: ${rec.time}: ${rec.message}'); |
| 93 }); | 93 }); |
| 94 | 94 |
| 95 var buildPath = Platform.script.resolve('build').path; | 95 var buildPath = Platform.script.resolve('build').toFilePath(); |
| 96 if (!new Directory(buildPath).existsSync()) { | 96 if (!new Directory(buildPath).existsSync()) { |
| 97 log.severe("The 'build/' directory was not found. Please run 'pub build'."); | 97 log.severe("The 'build/' directory was not found. Please run 'pub build'."); |
| 98 return; | 98 return; |
| 99 } | 99 } |
| 100 HttpServer.bind('0.0.0.0', 8080).then((server) { | 100 HttpServer.bind('0.0.0.0', 8080).then((server) { |
| 101 log.info("Search server is running on " | 101 log.info("Search server is running on " |
| 102 "'http://${Platform.localHostname}:8080/'"); | 102 "'http://${Platform.localHostname}:8080/'"); |
| 103 var router = new Router(server); | 103 var router = new Router(server); |
| 104 | 104 |
| 105 // The client will connect using a WebSocket. Upgrade requests to '/ws' and | 105 // The client will connect using a WebSocket. Upgrade requests to '/ws' and |
| 106 // forward them to 'handleWebSocket'. | 106 // forward them to 'handleWebSocket'. |
| 107 router.serve('/ws') | 107 router.serve('/ws') |
| 108 .transform(new WebSocketTransformer()) | 108 .transform(new WebSocketTransformer()) |
| 109 .listen(handleWebSocket); | 109 .listen(handleWebSocket); |
| 110 | 110 |
| 111 // Set up default handler. This will serve files from our 'build' directory. | 111 // Set up default handler. This will serve files from our 'build' directory. |
| 112 var virDir = new http_server.VirtualDirectory(buildPath); | 112 var virDir = new http_server.VirtualDirectory(buildPath); |
| 113 // Disable jail-root, as packages are local sym-links. | 113 // Disable jail-root, as packages are local sym-links. |
| 114 virDir.jailRoot = false; | 114 virDir.jailRoot = false; |
| 115 virDir.allowDirectoryListing = true; | 115 virDir.allowDirectoryListing = true; |
| 116 virDir.directoryHandler = (dir, request) { | 116 virDir.directoryHandler = (dir, request) { |
| 117 // Redirect directory-requests to index.html files. | 117 // Redirect directory-requests to index.html files. |
| 118 var indexUri = new Uri.file(dir.path).resolve('index.html'); | 118 var indexUri = new Uri.file(dir.path).resolve('index.html'); |
| 119 virDir.serveFile(new File(indexUri.path), request); | 119 virDir.serveFile(new File(indexUri.toFilePath()), request); |
| 120 }; | 120 }; |
| 121 virDir.serve(router.defaultStream); | 121 virDir.serve(router.defaultStream); |
| 122 }); | 122 }); |
| 123 } | 123 } |
| OLD | NEW |