Merge pull request #22 from gregbty/master

Replace express with native node calls
This commit is contained in:
Steve Sanderson
2015-12-14 12:50:00 +00:00
2 changed files with 14 additions and 1 deletions

View File

@@ -20,7 +20,13 @@ var server = http.createServer(function(req, res) {
if (!hasSentResult) {
hasSentResult = true;
if (errorValue) {
res.status(500).send(errorValue);
res.statusCode = 500;
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');

View File

@@ -1,3 +1,5 @@
using System;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
@@ -29,6 +31,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<T>(responseString);