diff --git a/red/nodes.js b/red/nodes.js index 4e813d2d4..5a2b560c3 100644 --- a/red/nodes.js +++ b/red/nodes.js @@ -241,8 +241,10 @@ module.exports.load = function() { } } else if (stats.isDirectory()) { // Ignore /.dirs/ and /lib/ - if (!/^(\..*|lib)$/.test(fn)) { + if (!/^(\..*|lib|icons)$/.test(fn)) { loadNodes(dir+"/"+fn); + } else if (fn === "icons") { + events.emit("node-icon-dir",dir+"/"+fn); } } }); diff --git a/red/server.js b/red/server.js index 876317bc9..78df31930 100644 --- a/red/server.js +++ b/red/server.js @@ -18,6 +18,7 @@ var fs = require('fs'); var util = require('util'); var createUI = require("./ui"); var redNodes = require("./nodes"); + //TODO: relocated user dir var flowfile = ''; @@ -74,6 +75,7 @@ function createServer(_server,settings) { }); }); } + function start() { console.log("\nWelcome to Node-RED\n===================\n"); util.log("[red] Loading palette nodes"); diff --git a/red/ui.js b/red/ui.js index 809ca8e4a..0592fc058 100644 --- a/red/ui.js +++ b/red/ui.js @@ -18,7 +18,17 @@ var util = require('util'); var crypto = require('crypto'); var fs = require("fs"); var app = express(); +var events = require("./events"); +var path = require("path"); +var icon_paths = [path.resolve(__dirname + '/../public/icons')]; + +events.on("node-icon-dir",function(dir) { + icon_paths.push(path.resolve(dir)); +}); + + +// TODO: nothing here uses settings... so does this need to be a function? function setupUI(settings) { // Need to ensure the url ends with a '/' so the static serving works @@ -31,10 +41,26 @@ function setupUI(settings) { } }); + app.get("/icons/:icon",function(req,res) { + for (var p in icon_paths) { + if (fs.existsSync(icon_paths[p]+'/'+req.params.icon)) { + res.sendfile(icon_paths[p]+'/'+req.params.icon); + return; + } + } + //TODO: create a default icon + res.sendfile(path.resolve(__dirname + '/../public/icons/arrow-in.png')); + }); + + app.use("/",express.static(__dirname + '/../public')); return app; } + + + + module.exports = setupUI;