OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 leap_server; |
| 6 |
5 import 'dart:io'; | 7 import 'dart:io'; |
6 | 8 |
7 class Conversation { | 9 class Conversation { |
8 HttpRequest request; | 10 HttpRequest request; |
9 HttpResponse response; | 11 HttpResponse response; |
10 | 12 |
11 static const String LEAP_LANDING_PAGE = 'samples/leap/index.html'; | 13 static const String LEAP_LANDING_PAGE = 'samples/leap/index.html'; |
12 | 14 |
13 static String landingPage = LEAP_LANDING_PAGE; | 15 static String landingPage = LEAP_LANDING_PAGE; |
14 | 16 |
(...skipping 17 matching lines...) Expand all Loading... |
32 redirect(String location) { | 34 redirect(String location) { |
33 response.statusCode = HttpStatus.FOUND; | 35 response.statusCode = HttpStatus.FOUND; |
34 response.headers.add(HttpHeaders.LOCATION, location); | 36 response.headers.add(HttpHeaders.LOCATION, location); |
35 done(); | 37 done(); |
36 } | 38 } |
37 | 39 |
38 handle() { | 40 handle() { |
39 String path = request.path; | 41 String path = request.path; |
40 if (path == '/') return redirect('/$landingPage'); | 42 if (path == '/') return redirect('/$landingPage'); |
41 if (path == '/favicon.ico') { | 43 if (path == '/favicon.ico') { |
42 path = '/lib/_internal/dartdoc/static/favicon.ico'; | 44 path = '/sdk/lib/_internal/dartdoc/static/favicon.ico'; |
43 } | 45 } |
44 if (path.contains('..') || path.contains('%')) return notFound(); | 46 if (path.contains('..') || path.contains('%')) return notFound(); |
45 var f = new File("./$path"); | 47 var f = new File("./$path"); |
46 f.exists().then((bool exists) { | 48 f.exists().then((bool exists) { |
47 if (!exists) return notFound(); | 49 if (!exists) return notFound(); |
48 if (path.endsWith('.dart')) { | 50 if (path.endsWith('.dart')) { |
49 response.headers.add(HttpHeaders.CONTENT_TYPE, "application/dart"); | 51 response.headers.add(HttpHeaders.CONTENT_TYPE, "application/dart"); |
50 } else if (path.endsWith('.ico')) { | 52 } else if (path.endsWith('.ico')) { |
51 response.headers.add(HttpHeaders.CONTENT_TYPE, "image/x-icon"); | 53 response.headers.add(HttpHeaders.CONTENT_TYPE, "image/x-icon"); |
52 } | 54 } |
(...skipping 12 matching lines...) Expand all Loading... |
65 if (arguments.length > 0) { | 67 if (arguments.length > 0) { |
66 Conversation.landingPage = arguments[0]; | 68 Conversation.landingPage = arguments[0]; |
67 } | 69 } |
68 var server = new HttpServer(); | 70 var server = new HttpServer(); |
69 var host = '127.0.0.1'; | 71 var host = '127.0.0.1'; |
70 var port = 8080; | 72 var port = 8080; |
71 server.listen(host, port); | 73 server.listen(host, port); |
72 print('HTTP server started on http://$host:$port/'); | 74 print('HTTP server started on http://$host:$port/'); |
73 server.defaultRequestHandler = Conversation.onRequest; | 75 server.defaultRequestHandler = Conversation.onRequest; |
74 } | 76 } |
OLD | NEW |