Register the express app to allow registration of urls.

This commit is contained in:
Michael Teeuw
2016-04-05 14:22:34 +02:00
parent f1dad4c9fb
commit 5420314784
3 changed files with 31 additions and 3 deletions

View File

@@ -6,6 +6,8 @@
*/
var Class = require('../../../js/class.js');
var express = require('express');
var path = require('path');
NodeHelper = Class.extend({
init: function() {
@@ -26,7 +28,7 @@ NodeHelper = Class.extend({
console.log(this.name + ' received a socket notification: ' + notification + ' - Payload: ' + payload);
},
/* setName(data)
/* setName(name)
* Set the module name.
*
* argument name string - Module name.
@@ -35,6 +37,15 @@ NodeHelper = Class.extend({
this.name = name;
},
/* setPath(path)
* Set the module path.
*
* argument name string - Module name.
*/
setPath: function(path) {
this.path = path;
},
/* sendSocketNotification(notification, payload)
* Send a socket notification to the node helper.
*
@@ -45,6 +56,20 @@ NodeHelper = Class.extend({
this.io.of(this.name).emit(notification, payload);
},
/* setExpressApp(app)
* Sets the express app object for this module.
* This allows you to host files from the created webserver.
*
* argument app Express app - The Express app object.
*/
setExpressApp: function(app) {
this.expressApp = app;
var publicPath = this.path + '/public';
app.use('/' + this.name, express.static(publicPath));
},
/* setSocketIO(io)
* Sets the socket io object for this module.
* Binds message receiver.