From bc359a3a4bd8a477ae10057c1ee16426fb12e197 Mon Sep 17 00:00:00 2001 From: Greg Beaty Date: Wed, 9 Dec 2015 16:18:00 -0500 Subject: [PATCH 1/4] Replace express with native node calls --- Microsoft.AspNet.NodeServices/Content/Node/entrypoint-http.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Microsoft.AspNet.NodeServices/Content/Node/entrypoint-http.js b/Microsoft.AspNet.NodeServices/Content/Node/entrypoint-http.js index f19c114b36..b9478c27e6 100644 --- a/Microsoft.AspNet.NodeServices/Content/Node/entrypoint-http.js +++ b/Microsoft.AspNet.NodeServices/Content/Node/entrypoint-http.js @@ -20,7 +20,8 @@ var server = http.createServer(function(req, res) { if (!hasSentResult) { hasSentResult = true; if (errorValue) { - res.status(500).send(errorValue); + res.statusCode = 500; + res.end(errorValue.toString()); } else if (typeof successValue !== 'string') { // Arbitrary object/number/etc - JSON-serialize it res.setHeader('Content-Type', 'application/json'); From 1e446b67974311e7069b20c00e63630803497ed5 Mon Sep 17 00:00:00 2001 From: Greg Beaty Date: Wed, 9 Dec 2015 16:36:30 -0500 Subject: [PATCH 2/4] Add exception stack to error response if available --- .../Content/Node/entrypoint-http.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Microsoft.AspNet.NodeServices/Content/Node/entrypoint-http.js b/Microsoft.AspNet.NodeServices/Content/Node/entrypoint-http.js index b9478c27e6..153d94f4b0 100644 --- a/Microsoft.AspNet.NodeServices/Content/Node/entrypoint-http.js +++ b/Microsoft.AspNet.NodeServices/Content/Node/entrypoint-http.js @@ -21,7 +21,12 @@ var server = http.createServer(function(req, res) { hasSentResult = true; if (errorValue) { res.statusCode = 500; - res.end(errorValue.toString()); + + if (errorValue.stack) { + res.end(errorValue.stack); + } else { + res.end(errorValue.toString()); + } } else if (typeof successValue !== 'string') { // Arbitrary object/number/etc - JSON-serialize it res.setHeader('Content-Type', 'application/json'); From f6bb28a71dd45505c6ceb15826473c9f1f237737 Mon Sep 17 00:00:00 2001 From: Greg Beaty Date: Wed, 9 Dec 2015 16:40:04 -0500 Subject: [PATCH 3/4] Add handling of error response from node process --- .../HostingModels/HttpNodeInstance.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Microsoft.AspNet.NodeServices/HostingModels/HttpNodeInstance.cs b/Microsoft.AspNet.NodeServices/HostingModels/HttpNodeInstance.cs index b863ad1fb4..67075271cf 100644 --- a/Microsoft.AspNet.NodeServices/HostingModels/HttpNodeInstance.cs +++ b/Microsoft.AspNet.NodeServices/HostingModels/HttpNodeInstance.cs @@ -29,6 +29,11 @@ namespace Microsoft.AspNet.NodeServices { var payload = new StringContent(payloadJson, Encoding.UTF8, "application/json"); var response = await client.PostAsync("http://localhost:" + this._portNumber, payload); var responseString = await response.Content.ReadAsStringAsync(); + + if (response.StatusCode != HttpStatusCode.OK) { + throw new Exception("Node module responded with error: " + responseString); + } + var responseIsJson = response.Content.Headers.ContentType.MediaType == "application/json"; if (responseIsJson) { return JsonConvert.DeserializeObject(responseString); From cda1663d1e7756acca8a1ff9da13c76474dc2858 Mon Sep 17 00:00:00 2001 From: Greg Beaty Date: Thu, 10 Dec 2015 01:52:01 -0500 Subject: [PATCH 4/4] Add missing imports --- Microsoft.AspNet.NodeServices/HostingModels/HttpNodeInstance.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Microsoft.AspNet.NodeServices/HostingModels/HttpNodeInstance.cs b/Microsoft.AspNet.NodeServices/HostingModels/HttpNodeInstance.cs index 67075271cf..d987df384f 100644 --- a/Microsoft.AspNet.NodeServices/HostingModels/HttpNodeInstance.cs +++ b/Microsoft.AspNet.NodeServices/HostingModels/HttpNodeInstance.cs @@ -1,3 +1,5 @@ +using System; +using System.Net; using System.Net.Http; using System.Text; using System.Text.RegularExpressions;