Skip to content

Latest commit

 

History

History
35 lines (23 loc) · 1.97 KB

node-red-server.md

File metadata and controls

35 lines (23 loc) · 1.97 KB
### Lab - enable Node-RED as a server application

Now you have a working Node-RED instance, you can add support for external applications (browsers, other applications on mobile devices, cloud apps, etc) to invoke services within Node-RED, to exchange information.

In this Lab, the goal will be to add support for incoming HTTP requests, from a browser, to request data be returned to display in the browser (i.e basic HTML).

  1. Add the necessary nodes
  2. Configure the nodes to support inbound HTTP and return content
  3. Deploy
  4. Test and validate via https://{{your-node-red-hostname}}/stage1

Using the techniques from the previous Lab, add a new flow to the canvas: stage1-flow.

Configure the http (inbound) node to accept the url /stage1: http-config

Configure the change node to set the response text, by chnaging msg.payload to the desired message. http-config

Configure the template node to be some simple HTML, and imbed the msg content from the flow, using mustache templating:

template-stage1.

The http response node does not usually need configuration, but is required as a final stage for returning data to a waiting http requester.

Now Deploy the changes. To test this flow, open a new browser tab or window and load https://{{your-node-red-hostname}}/stage1. All being well, you should receive the following response: stage1-result

Note that if you click on the Show me more link, you will receive a response like Cannot GET /stage2 - that's because "stage2" will be added in the next Lab.

Congratulations! - you have completed the first stage of establishing Node-RED as a web server application, and responding to HTTP requests with static data.