| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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("total:server"); | 5 #library("total:server"); |
| 6 | 6 |
| 7 #import("../../chat/chat_server_lib.dart"); | 7 #import("../../chat/chat_server_lib.dart"); |
| 8 #import("../../chat/http.dart"); | 8 #import("../../chat/http.dart"); |
| 9 #import("Dartc.dart"); | 9 #import("Dartc.dart"); |
| 10 #source("GetSpreadsheet.dart"); | 10 #source("GetSpreadsheet.dart"); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 addHandler("/adm/Adminz.js", | 54 addHandler("/adm/Adminz.js", |
| 55 (HTTPRequest request, HTTPResponse response) | 55 (HTTPRequest request, HTTPResponse response) |
| 56 => fileHandler(request, response, "${CLIENT_DIR}/Adminz.js")); | 56 => fileHandler(request, response, "${CLIENT_DIR}/Adminz.js")); |
| 57 addHandler("/adm/stop", stopServer); | 57 addHandler("/adm/stop", stopServer); |
| 58 addHandler("/adm/restart", restartServer); | 58 addHandler("/adm/restart", restartServer); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void restartServer(HTTPRequest request, HTTPResponse response) { | 61 void restartServer(HTTPRequest request, HTTPResponse response) { |
| 62 writeData(request, response, 'Restarting, KBBS', 'text/plain'); | 62 writeData(request, response, 'Restarting, KBBS', 'text/plain'); |
| 63 stop(); | 63 stop(); |
| 64 print("GRACEFUL RESTART!! TODO: make server exit gracefully"); | 64 print("GRACEFUL RESTART!!"); |
| 65 throw "GRACEFUL RESTART!! TODO: make server exit gracefully"; | 65 exit(42); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void stopServer(HTTPRequest request, HTTPResponse response) { | 68 void stopServer(HTTPRequest request, HTTPResponse response) { |
| 69 writeData(request, response, 'Exiting, KTHXBYE', 'text/plain'); | 69 writeData(request, response, 'Exiting, KTHXBYE', 'text/plain'); |
| 70 stop(); | 70 stop(); |
| 71 print("GRACEFUL EXIT!! TODO: make server exit gracefully"); | 71 print("GRACEFUL EXIT!!"); |
| 72 throw "GRACEFUL EXIT!! TODO: make server exit gracefully"; | 72 exit(0); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void writeData(HTTPRequest request, HTTPResponse response, String message, Str
ing mimeType) { | 75 void writeData(HTTPRequest request, HTTPResponse response, String message, Str
ing mimeType) { |
| 76 response.setHeader("Content-Type", mimeType); | 76 response.setHeader("Content-Type", mimeType); |
| 77 | 77 |
| 78 List<int> buffer = message.charCodes(); | 78 List<int> buffer = message.charCodes(); |
| 79 response.writeList(buffer, 0, buffer.length, null); | 79 response.writeList(buffer, 0, buffer.length, null); |
| 80 response.writeDone(); | 80 response.writeDone(); |
| 81 } | 81 } |
| 82 | 82 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 109 errorDiv.appendChild(errorSpan); | 109 errorDiv.appendChild(errorSpan); |
| 110 | 110 |
| 111 document.body.appendChild(errorDiv); | 111 document.body.appendChild(errorDiv); |
| 112 '''; | 112 '''; |
| 113 writeData(request, response, errorScript, "application/javascript"); | 113 writeData(request, response, errorScript, "application/javascript"); |
| 114 } | 114 } |
| 115 }); | 115 }); |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 | 118 |
| OLD | NEW |