Skip to content

Instantly share code, notes, and snippets.

@kevinswiber
Created July 20, 2015 23:53
Show Gist options
  • Select an option

  • Save kevinswiber/b9a8ea5c3da601581b13 to your computer and use it in GitHub Desktop.

Select an option

Save kevinswiber/b9a8ea5c3da601581b13 to your computer and use it in GitHub Desktop.
Embedding Node-RED inside Zetta.
var adapt = require('argo-connect');
var express = require("express");
var RED = require("node-red");
module.exports = function(server) {
var cloud = server.httpServer.cloud;
var httpServer = server.httpServer.server;
// Create an Express app
var app = express();
// Add a simple route for static content served from 'public'
app.use("/",express.static("public"));
// Create the settings object - see default settings.js file for other options
var settings = {
httpAdminRoot:"/red",
httpNodeRoot: "/api",
userDir:"./.nodered/",
functionGlobalContext: { } // enables global context
};
// Initialise the runtime with a server and settings
RED.init(server.httpServer.wss._server,settings);
// Serve the editor UI from /red
app.use(settings.httpAdminRoot,RED.httpAdmin);
// Serve the http nodes UI from /api
app.use(settings.httpNodeRoot,RED.httpNode);
cloud.route('/red/{splat: .*}', ['GET', 'POST', 'PUT', 'DELETE'], adapt(app));
cloud.route('/api/{splat: .*}', ['GET', 'POST', 'PUT', 'DELETE'], adapt(app));
// Start the runtime
RED.start();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment