From 957344b79bbfb93e606ad6aaffa59bcfbfb1e127 Mon Sep 17 00:00:00 2001 From: "Alwin J. Schuster" Date: Tue, 16 Jan 2024 08:37:32 +0100 Subject: [PATCH] feat: URL Data (#33) --- bridgeServer.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bridgeServer.js b/bridgeServer.js index 37e4435..e870c4d 100644 --- a/bridgeServer.js +++ b/bridgeServer.js @@ -4,14 +4,31 @@ import httpServer from "./httpServer"; class Request { constructor(rawRequest) { + const urlSplit = rawRequest.url.split('?'); + this.requestId = rawRequest.requestId; this.postData = rawRequest.postData; + + if(urlSplit.length > 1){ + const regex = /[?&]([^=#]+)=([^&#]*)/g; + const params = {}; + let match; + while (match = regex.exec(rawRequest.url)) { + params[match[1]] = match[2]; + } + this.getData = params; + }else + this.getData = undefined; + this.type = rawRequest.type; - this.url = rawRequest.url; + this.url = urlSplit[0]; } get data() { return JSON.parse(this.postData); } + get urlData() { + return this.getData; + } } class Response { constructor(requestId) {