mirror of
https://github.com/Lissy93/dashy.git
synced 2024-08-16 09:30:27 +03: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",
|
||||
"ajv": "^8.6.3",
|
||||
"axios": "^0.23.0",
|
||||
"body-parser": "^1.19.0",
|
||||
"connect": "^3.7.0",
|
||||
"connect-history-api-fallback": "^1.6.0",
|
||||
"crypto-js": "^4.1.1",
|
||||
"express": "^4.17.1",
|
||||
"js-yaml": "^4.1.0",
|
||||
"keycloak-js": "^15.0.2",
|
||||
"register-service-worker": "^1.6.2",
|
||||
"remedial": "^1.0.8",
|
||||
"rsup-progress": "^2.0.4",
|
||||
"serve-static": "^1.14.1",
|
||||
"simple-icons": "^5.14.0",
|
||||
"v-jsoneditor": "^1.4.2",
|
||||
"v-tooltip": "^2.1.3",
|
||||
@ -97,4 +95,4 @@
|
||||
"> 1%",
|
||||
"last 2 versions"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
78
server.js
78
server.js
@ -6,12 +6,10 @@
|
||||
* */
|
||||
|
||||
/* Include required node dependencies */
|
||||
const serveStatic = require('serve-static');
|
||||
const connect = require('connect');
|
||||
const express = require('express');
|
||||
const util = require('util');
|
||||
const dns = require('dns');
|
||||
const os = require('os');
|
||||
const bodyParser = require('body-parser');
|
||||
const history = require('connect-history-api-fallback');
|
||||
|
||||
/* 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 */
|
||||
const method = (m, mw) => (req, res, next) => (req.method === m ? mw(req, res, next) : next());
|
||||
|
||||
try {
|
||||
connect()
|
||||
.use(history())
|
||||
.use(bodyParser.json())
|
||||
// Serves up the main built application to the root
|
||||
.use(serveStatic(`${__dirname}/dist`))
|
||||
// During build, a custom page will be served before the app is available
|
||||
.use(serveStatic(`${__dirname}/public`, { index: 'default.html' }))
|
||||
// GET endpoint to run status of a given URL with GET request
|
||||
.use(ENDPOINTS.statusCheck, (req, res) => {
|
||||
try {
|
||||
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));
|
||||
const app = express()
|
||||
.use(history())
|
||||
.use(express.json())
|
||||
// Serves up the main built application to the root
|
||||
.use(express.static(`${__dirname}/dist`))
|
||||
.use(express.static(`${__dirname}/public`, { index: 'default.html' }))
|
||||
// GET endpoint to run status of a given URL with GET request
|
||||
.use(ENDPOINTS.statusCheck, (req, res) => {
|
||||
try {
|
||||
statusCheck(req.url, async (results) => {
|
||||
await res.end(results);
|
||||
});
|
||||
})
|
||||
// Finally, initialize the server then print welcome message
|
||||
.listen(port, () => {
|
||||
try { printWelcomeMessage(); } catch (e) { printWarning('Dashy is Starting...'); }
|
||||
} 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 (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…
Reference in New Issue
Block a user