Added ping handler. IO-406

This commit is contained in:
Patrick Fic
2021-02-22 17:04:13 -08:00
parent 50279d34ac
commit 1a364c91ef
4 changed files with 40 additions and 6 deletions

View File

@@ -11,6 +11,7 @@ using Newtonsoft.Json.Linq;
using BodyshopPartner.Models;
using ToastNotifications.Messages;
using System.Threading;
using System.Reflection;
namespace BodyshopPartner.Utils
{
@@ -36,6 +37,19 @@ namespace BodyshopPartner.Utils
(req, res, props) => { HandleQbPost(req, res); }
, "POST");
Route.Add("/ping/", (req, res, props) =>
{
hlog("Received a ping from ImEX.online");
res.WithCORS();
//res.AddHeader("Access-Control-Allow-Origin", "http://localhost:3000 https://localhost:3000 http://localhost:5000 https://localhost:5000 https://*.imex.online,imex.online");
res.Close();
}, "OPTIONS");
Route.Add("/ping/",
(req, res, props) => { HandlePing(req, res); }
, "POST");
logger.Trace("Starting HTTP server...");
hlog = HttpLogger;
@@ -125,6 +139,22 @@ namespace BodyshopPartner.Utils
}
private static void HandlePing(System.Net.HttpListenerRequest req, System.Net.HttpListenerResponse res)
{
logger.Trace("/ping/ - POST");
hlog("Received QuickBooks Receivable request.");
//Input will be an array of objects containing XMLs.
dynamic response = new JObject();
response.appver = Assembly.GetExecutingAssembly().GetName().Version.ToString();
response.qbpath = Properties.Settings.Default.QuickBooksFilePath;
var t = JsonConvert.SerializeObject(response);
res.WithCORS().AsText((string)t.ToString());
}
public static List<QbRequestItem> ParseRequest(System.Net.HttpListenerRequest req)
{
System.IO.Stream body = req.InputStream;