diff --git a/src/index.js b/src/index.js index c06e84c..95f0143 100644 --- a/src/index.js +++ b/src/index.js @@ -13,7 +13,9 @@ let os = require("os"); */ websrv.slisten((host, port) => { console.log("Server started on http://" + host + ":" + port); - open("http://" + host + ":" + port + "/dashboard"); + websrv.dashboardExist(()=>{ + open("http://" + host + ":" + port + "/dashboard"); + }) }); /** diff --git a/src/websrv/index.js b/src/websrv/index.js index be596b3..5c611c2 100644 --- a/src/websrv/index.js +++ b/src/websrv/index.js @@ -1,3 +1,5 @@ +const res = require("express/lib/response"); + module.exports = function (conf) { const websrvConfig = conf.webserver; const express = require("express"); @@ -11,6 +13,14 @@ module.exports = function (conf) { const internalRouter = require("./routes/internalRouter"); + app.dashboardExist = (cb) => { + let result = fs.existsSync(path.join(__dirname, "../../dashboard/")); + if (result) { + cb(); + } + return result; + }; + app.use((req, res, next) => { var start = process.hrtime(); res.on("finish", () => { @@ -26,10 +36,22 @@ module.exports = function (conf) { app.use(bodyParser.json()); app.use(cookieParser()); app.use("/api", internalRouter); - app.use("/dashboard", express.static(__dirname + "/../../dashboard/build")); - app.get("/dashboard/*", (req, res) => { - let indexPath = path.join(__dirname + "/../../dashboard/build/index.html"); - res.sendFile(indexPath); + + app.dashboardExist(() => { + app.use("/dashboard", express.static(__dirname + "/../../dashboard/build")); + app.get("/dashboard/*", (req, res) => { + let indexPath = path.join( + __dirname + "/../../dashboard/build/index.html" + ); + res.sendFile(indexPath); + }); + console.log( + "Dashboard is enabled on http://" + + websrvConfig.host + + ":" + + websrvConfig.port + + "/dashboard" + ); }); app.slisten = function (cb) {