mirror of
https://github.com/Lissy93/dashy.git
synced 2025-07-29 00:25:02 +02:00
🔥 Replaces serve-static, connect and body-parser with express
This commit is contained in:
parent
2543a8993e
commit
1bc978b704
@ -22,16 +22,14 @@
|
|||||||
"@sentry/vue": "^6.13.1",
|
"@sentry/vue": "^6.13.1",
|
||||||
"ajv": "^8.6.3",
|
"ajv": "^8.6.3",
|
||||||
"axios": "^0.23.0",
|
"axios": "^0.23.0",
|
||||||
"body-parser": "^1.19.0",
|
|
||||||
"connect": "^3.7.0",
|
|
||||||
"connect-history-api-fallback": "^1.6.0",
|
"connect-history-api-fallback": "^1.6.0",
|
||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
|
"express": "^4.17.1",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"keycloak-js": "^15.0.2",
|
"keycloak-js": "^15.0.2",
|
||||||
"register-service-worker": "^1.6.2",
|
"register-service-worker": "^1.6.2",
|
||||||
"remedial": "^1.0.8",
|
"remedial": "^1.0.8",
|
||||||
"rsup-progress": "^2.0.4",
|
"rsup-progress": "^2.0.4",
|
||||||
"serve-static": "^1.14.1",
|
|
||||||
"simple-icons": "^5.14.0",
|
"simple-icons": "^5.14.0",
|
||||||
"v-jsoneditor": "^1.4.2",
|
"v-jsoneditor": "^1.4.2",
|
||||||
"v-tooltip": "^2.1.3",
|
"v-tooltip": "^2.1.3",
|
||||||
@ -97,4 +95,4 @@
|
|||||||
"> 1%",
|
"> 1%",
|
||||||
"last 2 versions"
|
"last 2 versions"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
78
server.js
78
server.js
@ -6,12 +6,10 @@
|
|||||||
* */
|
* */
|
||||||
|
|
||||||
/* Include required node dependencies */
|
/* Include required node dependencies */
|
||||||
const serveStatic = require('serve-static');
|
const express = require('express');
|
||||||
const connect = require('connect');
|
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const dns = require('dns');
|
const dns = require('dns');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const bodyParser = require('body-parser');
|
|
||||||
const history = require('connect-history-api-fallback');
|
const history = require('connect-history-api-fallback');
|
||||||
|
|
||||||
/* Kick of some basic checks */
|
/* Kick of some basic checks */
|
||||||
@ -55,44 +53,40 @@ const printWarning = (msg, error) => {
|
|||||||
/* A middleware function for Connect, that filters requests based on method type */
|
/* A middleware function for Connect, that filters requests based on method type */
|
||||||
const method = (m, mw) => (req, res, next) => (req.method === m ? mw(req, res, next) : next());
|
const method = (m, mw) => (req, res, next) => (req.method === m ? mw(req, res, next) : next());
|
||||||
|
|
||||||
try {
|
const app = express()
|
||||||
connect()
|
.use(history())
|
||||||
.use(history())
|
.use(express.json())
|
||||||
.use(bodyParser.json())
|
// Serves up the main built application to the root
|
||||||
// Serves up the main built application to the root
|
.use(express.static(`${__dirname}/dist`))
|
||||||
.use(serveStatic(`${__dirname}/dist`))
|
.use(express.static(`${__dirname}/public`, { index: 'default.html' }))
|
||||||
// During build, a custom page will be served before the app is available
|
// GET endpoint to run status of a given URL with GET request
|
||||||
.use(serveStatic(`${__dirname}/public`, { index: 'default.html' }))
|
.use(ENDPOINTS.statusCheck, (req, res) => {
|
||||||
// GET endpoint to run status of a given URL with GET request
|
try {
|
||||||
.use(ENDPOINTS.statusCheck, (req, res) => {
|
statusCheck(req.url, async (results) => {
|
||||||
try {
|
await res.end(results);
|
||||||
statusCheck(req.url, async (results) => {
|
|
||||||
await res.end(results);
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
printWarning(`Error running status check for ${req.url}\n`, e);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// POST Endpoint used to save config, by writing conf.yml to disk
|
|
||||||
.use(ENDPOINTS.save, method('POST', (req, res) => {
|
|
||||||
try {
|
|
||||||
saveConfig(req.body, (results) => { res.end(results); });
|
|
||||||
} catch (e) {
|
|
||||||
res.end(JSON.stringify({ success: false, message: e }));
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
// GET endpoint to trigger a build, and respond with success status and output
|
|
||||||
.use(ENDPOINTS.rebuild, (req, res) => {
|
|
||||||
rebuild().then((response) => {
|
|
||||||
res.end(JSON.stringify(response));
|
|
||||||
}).catch((response) => {
|
|
||||||
res.end(JSON.stringify(response));
|
|
||||||
});
|
});
|
||||||
})
|
} catch (e) {
|
||||||
// Finally, initialize the server then print welcome message
|
printWarning(`Error running status check for ${req.url}\n`, e);
|
||||||
.listen(port, () => {
|
}
|
||||||
try { printWelcomeMessage(); } catch (e) { printWarning('Dashy is Starting...'); }
|
})
|
||||||
|
// POST Endpoint used to save config, by writing conf.yml to disk
|
||||||
|
.use(ENDPOINTS.save, method('POST', (req, res) => {
|
||||||
|
try {
|
||||||
|
saveConfig(req.body, (results) => { res.end(results); });
|
||||||
|
} catch (e) {
|
||||||
|
res.end(JSON.stringify({ success: false, message: e }));
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
// GET endpoint to trigger a build, and respond with success status and output
|
||||||
|
.use(ENDPOINTS.rebuild, (req, res) => {
|
||||||
|
rebuild().then((response) => {
|
||||||
|
res.end(JSON.stringify(response));
|
||||||
|
}).catch((response) => {
|
||||||
|
res.end(JSON.stringify(response));
|
||||||
});
|
});
|
||||||
} catch (error) {
|
});
|
||||||
printWarning('Sorry, a critical error occurred ', error);
|
|
||||||
}
|
// Finally, initialize the server then print welcome message
|
||||||
|
app.listen(port, () => {
|
||||||
|
try { printWelcomeMessage(); } catch (e) { printWarning('Dashy is Starting...'); }
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user