OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 /// Server component to display inference results using a web app. |
| 6 library dart2js_info.bin.inference.server; |
| 7 |
| 8 import 'dart:io'; |
| 9 import 'package:shelf/shelf.dart' as shelf; |
| 10 import 'package:shelf/shelf_io.dart' as shelf; |
| 11 import 'package:shelf_static/shelf_static.dart' as shelf_static; |
| 12 |
| 13 String jsonDataFile; |
| 14 String indexFile; |
| 15 String scriptFile; |
| 16 |
| 17 main(args) async { |
| 18 var host = 'localhost'; |
| 19 var port = 8080; |
| 20 |
| 21 jsonDataFile = args.length > 0 ? args[0] : 'out.js.stats.json'; |
| 22 indexFile = Platform.script.resolve('index.html').path; |
| 23 scriptFile = Platform.script.resolve('client.dart.js').path; |
| 24 |
| 25 await shelf.serve(_handler, host, port); |
| 26 } |
| 27 |
| 28 _handler(shelf.Request request) async { |
| 29 var path = request.url.path; |
| 30 if (path == 'data') { |
| 31 return new shelf.Response.ok(await new File(jsonDataFile).readAsString()); |
| 32 } |
| 33 if (path == 'client.dart.js') { |
| 34 return new shelf.Response.ok(await new File(scriptFile).readAsString(), |
| 35 headers: JS_HEADERS); |
| 36 } |
| 37 if (path.startsWith('file/')) { |
| 38 return _fileHandler(request.change(path: 'file')); |
| 39 } |
| 40 return new shelf.Response.ok(await new File(indexFile).readAsString(), |
| 41 headers: HTML_HEADERS); |
| 42 } |
| 43 |
| 44 final _fileHandler = shelf_static.createStaticHandler('/'); |
| 45 const HTML_HEADERS = const {'content-type': 'text/html'}; |
| 46 const JS_HEADERS = const {'content-type': 'text/javascript'}; |
OLD | NEW |