mirror of
https://github.com/Lissy93/dashy.git
synced 2024-10-26 14:38:03 +03:00
🥅 Adds try catch to server welcome msg (#477)
This commit is contained in:
parent
1294b43007
commit
e5ccdd9e97
27
server.js
27
server.js
@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* Note: The app must first be built (yarn build) before this script is run
|
|
||||||
* This is the main entry point for the application, a simple server that
|
* This is the main entry point for the application, a simple server that
|
||||||
* runs some checks, and then serves up the app from the ./dist directory
|
* runs some checks, and then serves up the app from the ./dist directory
|
||||||
* Also includes some routes for status checks/ ping and config saving
|
* Also imports some routes for status checks/ ping and config saving
|
||||||
|
* Note: The app must first be built (yarn build) before this script is run
|
||||||
* */
|
* */
|
||||||
|
|
||||||
/* Import built-in Node server modules */
|
/* Import built-in Node server modules */
|
||||||
@ -46,10 +46,15 @@ const getLocalIp = () => {
|
|||||||
|
|
||||||
/* Gets the users local IP and port, then calls to print welcome message */
|
/* Gets the users local IP and port, then calls to print welcome message */
|
||||||
const printWelcomeMessage = () => {
|
const printWelcomeMessage = () => {
|
||||||
getLocalIp().then(({ address }) => {
|
try {
|
||||||
const ip = address || 'localhost';
|
getLocalIp().then(({ address }) => {
|
||||||
console.log(printMessage(ip, port, isDocker)); // eslint-disable-line no-console
|
const ip = address || 'localhost';
|
||||||
});
|
console.log(printMessage(ip, port, isDocker)); // eslint-disable-line no-console
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
// Fetching info for welcome message failed, print simple msg instead
|
||||||
|
console.log(`Dashy server has started (${port})`); // eslint-disable-line no-console
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Just console.warns an error */
|
/* Just console.warns an error */
|
||||||
@ -65,7 +70,7 @@ const app = express()
|
|||||||
.use(express.static(path.join(__dirname, 'dist')))
|
.use(express.static(path.join(__dirname, 'dist')))
|
||||||
.use(express.static(path.join(__dirname, 'public'), { index: 'initialization.html' }))
|
.use(express.static(path.join(__dirname, 'public'), { index: 'initialization.html' }))
|
||||||
// Load middlewares for parsing JSON, and supporting HTML5 history routing
|
// Load middlewares for parsing JSON, and supporting HTML5 history routing
|
||||||
.use(express.json())
|
.use(express.json({ limit: '1mb' }))
|
||||||
.use(history())
|
.use(history())
|
||||||
// GET endpoint to run status of a given URL with GET request
|
// GET endpoint to run status of a given URL with GET request
|
||||||
.use(ENDPOINTS.statusCheck, (req, res) => {
|
.use(ENDPOINTS.statusCheck, (req, res) => {
|
||||||
@ -114,7 +119,13 @@ const app = express()
|
|||||||
});
|
});
|
||||||
|
|
||||||
/* Create HTTP server from app on port, and print welcome message */
|
/* Create HTTP server from app on port, and print welcome message */
|
||||||
http.createServer(app).listen(port, () => { printWelcomeMessage(); });
|
http.createServer(app)
|
||||||
|
.listen(port, () => {
|
||||||
|
printWelcomeMessage();
|
||||||
|
})
|
||||||
|
.on('error', (err) => {
|
||||||
|
printWarning('Unable to start Dashy\'s Node server', err);
|
||||||
|
});
|
||||||
|
|
||||||
/* Check, and if possible start SSL server too */
|
/* Check, and if possible start SSL server too */
|
||||||
sslServer(app);
|
sslServer(app);
|
||||||
|
Loading…
Reference in New Issue
Block a user