mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
Add error handling to node_helper startup sequence (#2945)
Fixes https://github.com/MichMich/MagicMirror/issues/2944 Also splits the Server js into a constrcutor and an open call to remove one callback parameter :-) Co-authored-by: veeck <michael@veeck.de>
This commit is contained in:
parent
7bd944391e
commit
64ed5a54cb
@ -34,6 +34,7 @@ Special thanks to: @rejas, @sdetweil
|
|||||||
|
|
||||||
- Correctly show apparent temperature in SMHI weather provider
|
- Correctly show apparent temperature in SMHI weather provider
|
||||||
- Ensure updatenotification module isn't shown when local is _ahead_ of remote
|
- Ensure updatenotification module isn't shown when local is _ahead_ of remote
|
||||||
|
- Handle node_helper errors during startup (#2944)
|
||||||
- Possibility to change FontAwesome class in calendar, so icons like `fab fa-facebook-square` works.
|
- Possibility to change FontAwesome class in calendar, so icons like `fab fa-facebook-square` works.
|
||||||
- Fix cors problems with newsfeed articles (as far as possible), allow disabling cors per feed with option `useCorsProxy: false` (#2840)
|
- Fix cors problems with newsfeed articles (as far as possible), allow disabling cors per feed with option `useCorsProxy: false` (#2840)
|
||||||
|
|
||||||
|
21
js/app.js
21
js/app.js
@ -223,27 +223,38 @@ function App() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadModules(modules, function () {
|
loadModules(modules, function () {
|
||||||
httpServer = new Server(config, function (app, io) {
|
httpServer = new Server(config);
|
||||||
|
const { app, io } = httpServer.open();
|
||||||
Log.log("Server started ...");
|
Log.log("Server started ...");
|
||||||
|
|
||||||
const nodePromises = [];
|
const nodePromises = [];
|
||||||
|
|
||||||
for (let nodeHelper of nodeHelpers) {
|
for (let nodeHelper of nodeHelpers) {
|
||||||
nodeHelper.setExpressApp(app);
|
nodeHelper.setExpressApp(app);
|
||||||
nodeHelper.setSocketIO(io);
|
nodeHelper.setSocketIO(io);
|
||||||
|
|
||||||
|
try {
|
||||||
nodePromises.push(nodeHelper.start());
|
nodePromises.push(nodeHelper.start());
|
||||||
|
} catch (error) {
|
||||||
|
Log.error(`Error when starting node_helper for module ${nodeHelper.name}:`);
|
||||||
|
Log.error(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.allSettled(nodePromises).then(() => {
|
Promise.allSettled(nodePromises).then((results) => {
|
||||||
Log.log("Sockets connected & modules started ...");
|
// Log errors that happened during async node_helper startup
|
||||||
|
results.forEach((result) => {
|
||||||
|
if (result.status === "rejected") {
|
||||||
|
Log.error(result.reason);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Log.log("Sockets connected & modules started ...");
|
||||||
if (typeof callback === "function") {
|
if (typeof callback === "function") {
|
||||||
callback(config);
|
callback(config);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
19
js/server.js
19
js/server.js
@ -5,7 +5,6 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const app = require("express")();
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const ipfilter = require("express-ipfilter").IpFilter;
|
const ipfilter = require("express-ipfilter").IpFilter;
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
@ -19,14 +18,15 @@ const Utils = require("./utils.js");
|
|||||||
* Server
|
* Server
|
||||||
*
|
*
|
||||||
* @param {object} config The MM config
|
* @param {object} config The MM config
|
||||||
* @param {Function} callback Function called when done.
|
|
||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
function Server(config, callback) {
|
function Server(config) {
|
||||||
|
const app = express();
|
||||||
const port = process.env.MM_PORT || config.port;
|
const port = process.env.MM_PORT || config.port;
|
||||||
const serverSockets = new Set();
|
const serverSockets = new Set();
|
||||||
|
|
||||||
let server = null;
|
let server = null;
|
||||||
|
|
||||||
|
this.open = function () {
|
||||||
if (config.useHttps) {
|
if (config.useHttps) {
|
||||||
const options = {
|
const options = {
|
||||||
key: fs.readFileSync(config.httpsPrivateKey),
|
key: fs.readFileSync(config.httpsPrivateKey),
|
||||||
@ -52,7 +52,6 @@ function Server(config, callback) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Log.log(`Starting server on port ${port} ... `);
|
Log.log(`Starting server on port ${port} ... `);
|
||||||
|
|
||||||
server.listen(port, config.address || "localhost");
|
server.listen(port, config.address || "localhost");
|
||||||
|
|
||||||
if (config.ipWhitelist instanceof Array && config.ipWhitelist.length === 0) {
|
if (config.ipWhitelist instanceof Array && config.ipWhitelist.length === 0) {
|
||||||
@ -69,8 +68,8 @@ function Server(config, callback) {
|
|||||||
res.status(403).send("This device is not allowed to access your mirror. <br> Please check your config.js or config.js.sample to change this.");
|
res.status(403).send("This device is not allowed to access your mirror. <br> Please check your config.js or config.js.sample to change this.");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
app.use(helmet(config.httpHeaders));
|
|
||||||
|
|
||||||
|
app.use(helmet(config.httpHeaders));
|
||||||
app.use("/js", express.static(__dirname));
|
app.use("/js", express.static(__dirname));
|
||||||
|
|
||||||
// TODO add tests directory only when running tests?
|
// TODO add tests directory only when running tests?
|
||||||
@ -127,9 +126,11 @@ function Server(config, callback) {
|
|||||||
res.send(html);
|
res.send(html);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof callback === "function") {
|
return {
|
||||||
callback(app, io);
|
app,
|
||||||
}
|
io
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
this.close = function () {
|
this.close = function () {
|
||||||
for (const socket of serverSockets.values()) {
|
for (const socket of serverSockets.values()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user