| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 import 'dart:io'; | 5 import 'dart:io'; |
| 6 import 'package:http_server/http_server.dart' as http_server; | 6 import 'package:http_server/http_server.dart' as http_server; |
| 7 import 'package:route/server.dart'; | 7 import 'package:route/server.dart'; |
| 8 import 'package:path/path.dart'; | 8 import 'package:path/path.dart'; |
| 9 import 'package:http_server/http_server.dart'; | 9 import 'package:http_server/http_server.dart'; |
| 10 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // /file takes a parameter [path] and serves the content of the specified file | 64 // /file takes a parameter [path] and serves the content of the specified file |
| 65 // in path relative to [dir] | 65 // in path relative to [dir] |
| 66 // | 66 // |
| 67 // /map serves the name of the map file such that its content can be requested | 67 // /map serves the name of the map file such that its content can be requested |
| 68 // with a /file request as above. | 68 // with a /file request as above. |
| 69 void startServer() { | 69 void startServer() { |
| 70 String root = fromUri(Platform.script.resolve('../build/web/')); | 70 String root = fromUri(Platform.script.resolve('../build/web/')); |
| 71 Directory directory = new Directory(root); | 71 Directory directory = new Directory(root); |
| 72 if (!directory.existsSync()) { | 72 if (!directory.existsSync()) { |
| 73 print("Directory '$root' does not exist. " | 73 print("Directory '$root' does not exist. " |
| 74 "Run 'pub build' to generate the output."); | 74 "Run 'pub build' to generate the output."); |
| 75 exit(-1); | 75 exit(-1); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // Use port 0 to get an ephemeral port. | 78 // Use port 0 to get an ephemeral port. |
| 79 int port = 0; | 79 int port = 0; |
| 80 HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, port).then((server) { | 80 HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, port).then((server) { |
| 81 port = server.port; | 81 port = server.port; |
| 82 print("Source mapping server is running on " | 82 print("Source mapping server is running on " |
| 83 "'http://${server.address.address}:$port/'"); | 83 "'http://${server.address.address}:$port/'"); |
| 84 Router router = new Router(server) | 84 Router router = new Router(server) |
| 85 ..serve('/file').listen(handleFile) | 85 ..serve('/file').listen(handleFile) |
| 86 ..serve('/map').listen(handleSourceMapFile); | 86 ..serve('/map').listen(handleSourceMapFile); |
| 87 | 87 |
| 88 // Set up default handler. This will serve files from our 'build' | 88 // Set up default handler. This will serve files from our 'build' |
| 89 // directory. Disable jail root, as packages are local symlinks. | 89 // directory. Disable jail root, as packages are local symlinks. |
| 90 VirtualDirectory virDir = new http_server.VirtualDirectory(root) | 90 VirtualDirectory virDir = new http_server.VirtualDirectory(root) |
| 91 ..jailRoot = false | 91 ..jailRoot = false |
| 92 ..allowDirectoryListing = true; | 92 ..allowDirectoryListing = true; |
| 93 | 93 |
| 94 virDir.directoryHandler = (dir, request) { | 94 virDir.directoryHandler = (dir, request) { |
| 95 // Redirect directory requests to index.html files. | 95 // Redirect directory requests to index.html files. |
| 96 Uri indexUri = new Uri.file(dir.path).resolve('display.html'); | 96 Uri indexUri = new Uri.file(dir.path).resolve('display.html'); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 126 command = '/usr/bin/google-chrome'; | 126 command = '/usr/bin/google-chrome'; |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 print('Starting browser: ${command} ${url}'); | 130 print('Starting browser: ${command} ${url}'); |
| 131 Process.run(command, ['$url']).then((ProcessResult result) { | 131 Process.run(command, ['$url']).then((ProcessResult result) { |
| 132 if (result.exitCode != 0) { | 132 if (result.exitCode != 0) { |
| 133 print(result.stderr); | 133 print(result.stderr); |
| 134 } | 134 } |
| 135 }); | 135 }); |
| 136 } | 136 } |
| OLD | NEW |