From a9879b7c8a1049b18d8cbc5cd06b302fac088203 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Thu, 17 Mar 2016 00:51:08 +0000 Subject: [PATCH] Arrow keys do are not handled by onkeypress on all browsers. Wonderful. Use onkeydown instead. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3170 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/httpd.js | 10 +++++++++- core/terminal.js | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/core/httpd.js b/core/httpd.js index 39fd8077..5e372e4b 100644 --- a/core/httpd.js +++ b/core/httpd.js @@ -60,6 +60,7 @@ function Response(request, client) { var kStatusText = { 200: 'OK', 303: 'See other', + 403: 'Forbidden', 404: 'File not found', 500: 'Internal server error', }; @@ -143,8 +144,15 @@ function handleRequest(request, response) { if (handler) { try { - handler.invoke(request, response); + var promise = handler.invoke(request, response); + if (promise) { + promise.catch(function(error) { + print(error); + response.reportError(error); + }); + } } catch (error) { + print(error); response.reportError(error); } } else { diff --git a/core/terminal.js b/core/terminal.js index 82e8b34e..3e42b344 100644 --- a/core/terminal.js +++ b/core/terminal.js @@ -243,6 +243,24 @@ function handler(request, response, packageOwner, packageName, uri) { process.terminal.print(error); }); } + } else if (uri === "/post") { + if (isNewSession) { + response.writeHead(403, {"Content-Type": "text/plain; charset=utf-8"}); + print("post too soon"); + response.end("Too soon."); + } else { + var payload = JSON.parse(request.body); + return invoke(process.eventHandlers['onPost'], [payload]).then(function() { + response.writeHead(200, { + "Content-Type": "text/plain; charset=utf-8", + "Content-Length": "0", + "Cache-Control": "no-cache, no-store, must-revalidate", + "Pragma": "no-cache", + "Expires": "0", + }); + response.end(""); + }); + } } else if (uri === "/receive") { if (isNewSession) { var data = JSON.stringify({