diff --git a/core/httpd.js b/core/httpd.js index 5e372e4b..e141e18b 100644 --- a/core/httpd.js +++ b/core/httpd.js @@ -147,7 +147,6 @@ function handleRequest(request, response) { var promise = handler.invoke(request, response); if (promise) { promise.catch(function(error) { - print(error); response.reportError(error); }); } diff --git a/core/terminal.js b/core/terminal.js index 3e42b344..523a6b3d 100644 --- a/core/terminal.js +++ b/core/terminal.js @@ -201,13 +201,17 @@ function handler(request, response, packageOwner, packageName, uri) { options.userName = credentials.session.name; } options.credentials = credentials; - var sessionId = form.decodeForm(request.query).sessionId; - var isNewSession = false; - if (!getSessionProcess(packageOwner, packageName, sessionId, {create: false})) { - sessionId = makeSessionId(); - isNewSession = true; + if (uri == "/submit") { + process = getServiceProcess(packageOwner, packageName, "submit"); + } else { + var sessionId = form.decodeForm(request.query).sessionId; + var isNewSession = false; + if (!getSessionProcess(packageOwner, packageName, sessionId, {create: false})) { + sessionId = makeSessionId(); + isNewSession = true; + } + process = getSessionProcess(packageOwner, packageName, sessionId, options); } - process = getSessionProcess(packageOwner, packageName, sessionId, options); process.lastActive = Date.now(); if (uri === "/send") { @@ -243,14 +247,10 @@ 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() { + } else if (uri === "/submit") { + return process.ready.then(function() { + var payload = form.decodeForm(request.body, form.decodeForm(request.query)); + return invoke(process.eventHandlers['onSubmit'], [payload]).then(function() { response.writeHead(200, { "Content-Type": "text/plain; charset=utf-8", "Content-Length": "0", @@ -258,9 +258,9 @@ function handler(request, response, packageOwner, packageName, uri) { "Pragma": "no-cache", "Expires": "0", }); - response.end(""); + return response.end(""); }); - } + }); } else if (uri === "/receive") { if (isNewSession) { var data = JSON.stringify({