Skip to content

Commit 2894d29

Browse files
committed
Adjust routes to make code slightly more followable.
Log all of the things.
1 parent 0454ea5 commit 2894d29

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

component-chatbot.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ module.exports = function(RED) {
3434

3535
RED.httpNode.post(`/nr-component-chatbot/${uniqueID}`, function(req, res) {
3636

37+
debug(`Path ${req.originalUrl} hit.`);
3738
node.updateWires(wires[node.id]);
3839

39-
if(process.env.ADDITIONAL_DEBUG === true){
40+
if(process.env.ADDITIONAL_DEBUG){
4041
debug("REQUEST:", req);
4142
debug("REQUEST_BODY:", req.body);
4243
}
@@ -73,6 +74,8 @@ module.exports = function(RED) {
7374

7475
node.on('input', function(msg) {
7576

77+
debug('Reply node recieved input:', JSON.stringify(msg));
78+
7679
if(msg['nr-component-chatbot-id']){
7780
connectionQueue[ msg[ 'nr-component-chatbot-id' ] ].messages.push(msg.payload);
7881
}
@@ -82,6 +85,7 @@ module.exports = function(RED) {
8285
RED.httpNode.get("/nr-component-chatbot/get-id", function(req, res) {
8386

8487
const queueUUID = uuid();
88+
debug('New UUID for chatbot requested and created:', queueUUID);
8589

8690
connectionQueue[queueUUID] = {
8791
messages : []
@@ -94,7 +98,9 @@ module.exports = function(RED) {
9498

9599
});
96100

97-
RED.httpNode.get(`/nr-component-chatbot/:queueUUID`, function(req, res) {
101+
RED.httpNode.get(`/nr-component-chatbot/check-messages/:queueUUID`, function(req, res) {
102+
103+
debug(`Checking messages at ${req.originalUrl}`);
98104

99105
node.updateWires(wires[node.id]);
100106

@@ -107,6 +113,8 @@ module.exports = function(RED) {
107113

108114
} else {
109115

116+
debug(`Request tried to check for message queue that doesn't exist: ${req.params.queueUUID}`);
117+
110118
res.status(404);
111119
res.json({
112120
status : 'err',

component-scripts/chatbot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@
392392
const checker = setInterval(function(){
393393

394394
if(SESSION_UUID){
395-
fetch(`${chatbotOrigin}/nr-component-chatbot/${SESSION_UUID}`)
395+
fetch(`${chatbotOrigin}/nr-component-chatbot/check-messages/${SESSION_UUID}`)
396396
.then(function(res){
397397
if(res.ok){
398398
return res.json();

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-contrib-web-components",
3-
"version": "0.2.13",
3+
"version": "0.3.0",
44
"description": "Expose useful functionality to Node-RED developers through the magic of Web Components",
55
"scripts": {
66
"test": "echo \"Error: no test specified\" && exit 1"

0 commit comments

Comments
 (0)