Hello,
I would like to achieve the following thing. I want to have a server in Node-red which can be used for chat - but only server! I want to make AJAX (really AJAX, not sockets) on client side in my IDE (not in node-red).
How can I do that? How can I build the server in order to be able to use AJAX on clients side in my IDE?
Node-RED is built using Node.js and ExpressJS. So you already have a server available to you if you are writing custom nodes. Actually, NR uses 2 servers, one for admin and one for user.
You can use those in your own custom nodes.
If you don't want a custom node, you can use the http-in node which adds a listening path to the existing user server. Check out the docs for that.
Ok, thanks. How would it work now? Users will join on the page: http://127.0.0.1:1880/chat, right? Then what should happen in that function? or will it stay the same? (return msg)
With the flow you have, it will be triggered when the browser goes to /chat. The browser will receive whatever msg.payload you pass on to the HTTP Response node.
So in this case, that would be the HTML content of the webpage you want them to see. You can use the Template node as a convenient way to provide that content in your flow, rather than the Function node.
So start with a fixed message, you need to decide if you are going to use true AJAX and send it as xml, or choose to use JSON instead and then use your template node to create the reply message.
You have the URL of your that you defined in your HTTP-IN node.
How you program the client in your IDE isn't really a Node-RED issue...
Yes, i understand AJAX, I just have a proble to do it with node-red.
I have localhost:1880/chat as an endpoint, where I am sending "message" which was written by user, but in response I am getting EMPTY body. I would need to send back that message in response. What might be wrong?
In my flow I have: Post - function(return msg) - http response
Rather than showing us what you have in the client, show us what you have in node-red. Put a debug node on the output of the http node and make sure it is receiving the message ok. If that looks ok then export your flow and paste it here.
[Edit] I should have said then put a debug on the output of the function node and check that shows what you expect, if you still can't work it out then post the flow.