add dashboard enable check + functionality

This commit is contained in:
lucaspalomodevelop 2022-06-01 21:38:24 +02:00
parent 8694ced81d
commit 60dd9404b4
2 changed files with 29 additions and 5 deletions

View File

@ -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");
})
});
/**

View File

@ -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) {