How to create a web server beside TheThingBox

For release 2.6 and after

  • Create a file userapp.js into /root/thethingbox/node_modules/router/
  • Fill this file with :

    module.exports = function(app, dir, RED, settings_nodered) { var express = require(“express”); var ret = true; var userapp = express(); var app_path = “/root/userdir/server”; var url_path = “/userapp”; try { userapp.set(‘views’, app_path); userapp.use(“/”, express.static(app_path)); app.use(url_path, userapp); } catch (e) { ret = false } return ret; }

Note : /userapp will be the url to access to your server => thethingbox.local/userapp

  • Update the file /root/thethingbox/node_modules/router/package.json to add your server :

    { “name”: “thethingbox-router”, “description”: “Express route to use for thethingbox”, “version”: “0.0.1”, “routes”: [{ “name”: “CGU”, “file”: “cgu.js” }, { “name”: “icon”, “file”: “favicon.js” }, { “name”: “Node-RED”, “file”: “red.js” }, { “name”: “User app”, “file”: “userapp.js” }] }

  • Create a folder server into /root/userdir and put your files in it.

    sudo service thethingbox restart
    

For release 2.5 and before

  • Update the file thethingbox.js into /root/rhethingbox
  • after the line var app = express(); , add :
var userapp = express();
var app_path = "/root/userdir/server";
var url_path = "/userapp";

userapp.set('views', app_path);
userapp.use("/", express.static(app_path));
app.use(url_path, userapp);

Note : /userapp will be the url to access to your server => thethingbox.local/userapp

  • Create a folder server into /root/userdir and put your files in it.
  • Then, restart your thingbox :
sudo service thethingbox restart