Skip to content

Instantly share code, notes, and snippets.

@LennartHennigs
Created September 12, 2017 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LennartHennigs/0b5dd08daaa01a56f6a0a41dd9474072 to your computer and use it in GitHub Desktop.
Save LennartHennigs/0b5dd08daaa01a56f6a0a41dd9474072 to your computer and use it in GitHub Desktop.
serve index for the httpStatic directory

This flow checks wether the httpStatic directory contains anindex.html or index.htm file. If not, it creates a directory index.

It uses the node-red-contrib-fs-ops to read directory and file contents.

http_Static_flow.png

[{"id":"1c5e5e25.73f2f2","type":"tab","label":"create directory index","disabled":false,"info":""},{"id":"31847169.c498be","type":"http in","z":"1c5e5e25.73f2f2","name":"","url":"/","method":"get","upload":false,"swaggerDoc":"","x":70,"y":80,"wires":[["995abb6f.b3edd"]]},{"id":"995abb6f.b3edd","type":"fs-ops-dir","z":"1c5e5e25.73f2f2","name":"","path":"/home/pi/Public","pathType":"str","filter":"*","filterType":"str","dir":"files","dirType":"msg","x":220,"y":80,"wires":[["c08c98b6.8107c"]]},{"id":"3e227f9.1d26","type":"template","z":"1c5e5e25.73f2f2","name":"create dir index","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n<body>\n<h1>Directory Index</h1>\n{{#files}}\n <div><a href=\"{{.}}\">./{{.}}</a></div>\n{{/files}}\n</body>\n</html>","output":"str","x":660,"y":120,"wires":[["12ba298b.108cce"]]},{"id":"c08c98b6.8107c","type":"switch","z":"1c5e5e25.73f2f2","name":"has index?","property":"files","propertyType":"msg","rules":[{"t":"cont","v":"index.html","vt":"str"},{"t":"cont","v":"index.htm","vt":"str"},{"t":"else"}],"checkall":"false","outputs":3,"x":390,"y":80,"wires":[["a1a3cd5d.5a1808"],["8c72df6b.4d4af8"],["3e227f9.1d26"]],"outputLabels":["index.html exists","",""]},{"id":"12ba298b.108cce","type":"http response","z":"1c5e5e25.73f2f2","name":"","statusCode":"","headers":{},"x":830,"y":80,"wires":[]},{"id":"a1a3cd5d.5a1808","type":"file in","z":"1c5e5e25.73f2f2","name":"","filename":"/home/pi/Public/index.html","format":"utf8","chunk":false,"sendError":false,"x":620,"y":40,"wires":[["12ba298b.108cce"]]},{"id":"8c72df6b.4d4af8","type":"file in","z":"1c5e5e25.73f2f2","name":"","filename":"/home/pi/Public/index.htm","format":"utf8","chunk":false,"sendError":false,"x":620,"y":80,"wires":[["12ba298b.108cce"]]},{"id":"aba239e8.eb2fa8","type":"comment","z":"1c5e5e25.73f2f2","name":"if there is no index.htm(l) file, the flow returns an index","info":"","x":220,"y":180,"wires":[]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment