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; | 5 library leap_server; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 class Conversation { | 9 class Conversation { |
10 HttpRequest request; | 10 HttpRequest request; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 75 } |
76 setUpErrorHandler(); | 76 setUpErrorHandler(); |
77 f.openRead().pipe(response); | 77 f.openRead().pipe(response); |
78 }); | 78 }); |
79 } | 79 } |
80 | 80 |
81 static onRequest(HttpRequest request) { | 81 static onRequest(HttpRequest request) { |
82 new Conversation(request, request.response).handle(); | 82 new Conversation(request, request.response).handle(); |
83 } | 83 } |
84 | 84 |
85 static onError(AsyncError e) { | 85 static onError(error) { |
86 if (e.error is HttpParserException) { | 86 if (error is HttpParserException) { |
87 print('Error: ${e.error.message}'); | 87 print('Error: ${error.message}'); |
88 } else { | 88 } else { |
89 print('Error: ${e.error}'); | 89 print('Error: ${error}'); |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 String htmlInfo(String title, String text) { | 93 String htmlInfo(String title, String text) { |
94 return """ | 94 return """ |
95 <!DOCTYPE html> | 95 <!DOCTYPE html> |
96 <html lang='en'> | 96 <html lang='en'> |
97 <head> | 97 <head> |
98 <title>$title</title> | 98 <title>$title</title> |
99 </head> | 99 </head> |
100 <body> | 100 <body> |
101 <h1>$title</h1> | 101 <h1>$title</h1> |
102 <p>$text</p> | 102 <p>$text</p> |
103 </body> | 103 </body> |
104 </html> | 104 </html> |
105 """; | 105 """; |
106 } | 106 } |
107 } | 107 } |
108 | 108 |
109 main() { | 109 main() { |
110 List<String> arguments = new Options().arguments; | 110 List<String> arguments = new Options().arguments; |
111 if (arguments.length > 0) { | 111 if (arguments.length > 0) { |
112 Conversation.landingPage = arguments[0]; | 112 Conversation.landingPage = arguments[0]; |
113 } | 113 } |
114 var host = '127.0.0.1'; | 114 var host = '127.0.0.1'; |
115 HttpServer.bind(host, 0).then((HttpServer server) { | 115 HttpServer.bind(host, 0).then((HttpServer server) { |
116 print('HTTP server started on http://$host:${server.port}/'); | 116 print('HTTP server started on http://$host:${server.port}/'); |
117 server.listen(Conversation.onRequest, onError: Conversation.onError); | 117 server.listen(Conversation.onRequest, onError: Conversation.onError); |
118 }).catchError((e) { | 118 }).catchError((e) { |
119 print("HttpServer.bind error: ${e.error}"); | 119 print("HttpServer.bind error: $e"); |
120 exit(1); | 120 exit(1); |
121 }); | 121 }); |
122 } | 122 } |
OLD | NEW |