mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-28 04:02:12 +00:00
Register the express app to allow registration of urls.
This commit is contained in:
parent
f1dad4c9fb
commit
5420314784
@ -7,6 +7,7 @@ const Server = require(__dirname + '/server.js');
|
|||||||
const spawn = require('child_process').spawn;
|
const spawn = require('child_process').spawn;
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const defaultModules = require(__dirname + '/../modules/default/defaultmodules.js');
|
const defaultModules = require(__dirname + '/../modules/default/defaultmodules.js');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
var config = {};
|
var config = {};
|
||||||
@ -80,6 +81,7 @@ function loadModule(module) {
|
|||||||
var Module = require(helperPath);
|
var Module = require(helperPath);
|
||||||
var m = new Module();
|
var m = new Module();
|
||||||
m.setName(moduleName);
|
m.setName(moduleName);
|
||||||
|
m.setPath(path.resolve(moduleFolder));
|
||||||
nodeHelpers.push(m);
|
nodeHelpers.push(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,11 +110,12 @@ loadConfig(function(c) {
|
|||||||
|
|
||||||
loadModules(modules);
|
loadModules(modules);
|
||||||
|
|
||||||
var server = new Server(config, function(io) {
|
var server = new Server(config, function(app, io) {
|
||||||
console.log('Server started ...');
|
console.log('Server started ...');
|
||||||
|
|
||||||
for (var h in nodeHelpers) {
|
for (var h in nodeHelpers) {
|
||||||
var nodeHelper = nodeHelpers[h];
|
var nodeHelper = nodeHelpers[h];
|
||||||
|
nodeHelper.setExpressApp(app);
|
||||||
nodeHelper.setSocketIO(io);
|
nodeHelper.setSocketIO(io);
|
||||||
nodeHelper.start();
|
nodeHelper.start();
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ var Server = function(config, callback) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
callback(io);
|
callback(app, io);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
27
modules/node_modules/node_helper/index.js
generated
vendored
27
modules/node_modules/node_helper/index.js
generated
vendored
@ -6,6 +6,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var Class = require('../../../js/class.js');
|
var Class = require('../../../js/class.js');
|
||||||
|
var express = require('express');
|
||||||
|
var path = require('path');
|
||||||
|
|
||||||
NodeHelper = Class.extend({
|
NodeHelper = Class.extend({
|
||||||
init: function() {
|
init: function() {
|
||||||
@ -26,7 +28,7 @@ NodeHelper = Class.extend({
|
|||||||
console.log(this.name + ' received a socket notification: ' + notification + ' - Payload: ' + payload);
|
console.log(this.name + ' received a socket notification: ' + notification + ' - Payload: ' + payload);
|
||||||
},
|
},
|
||||||
|
|
||||||
/* setName(data)
|
/* setName(name)
|
||||||
* Set the module name.
|
* Set the module name.
|
||||||
*
|
*
|
||||||
* argument name string - Module name.
|
* argument name string - Module name.
|
||||||
@ -35,6 +37,15 @@ NodeHelper = Class.extend({
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/* setPath(path)
|
||||||
|
* Set the module path.
|
||||||
|
*
|
||||||
|
* argument name string - Module name.
|
||||||
|
*/
|
||||||
|
setPath: function(path) {
|
||||||
|
this.path = path;
|
||||||
|
},
|
||||||
|
|
||||||
/* sendSocketNotification(notification, payload)
|
/* sendSocketNotification(notification, payload)
|
||||||
* Send a socket notification to the node helper.
|
* Send a socket notification to the node helper.
|
||||||
*
|
*
|
||||||
@ -45,6 +56,20 @@ NodeHelper = Class.extend({
|
|||||||
this.io.of(this.name).emit(notification, payload);
|
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)
|
/* setSocketIO(io)
|
||||||
* Sets the socket io object for this module.
|
* Sets the socket io object for this module.
|
||||||
* Binds message receiver.
|
* Binds message receiver.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user