Skip to content

Commit c1e8d62

Browse files
Saif Al-Dilaimidrew-gross
Saif Al-Dilaimi
authored andcommitted
gives the developer feedback if something is wrong with the icons directory (parse-community#363)
* icons * moved directory to index.js * final parse-dashboard now check for the icons directory and also each app icon * removed log call and fixed code indention * catch error if folder doesn't exist at start and show error why the dashboard couldn’t be started
1 parent 0b903f4 commit c1e8d62

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

Parse-Dashboard/app.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const express = require('express');
33
const basicAuth = require('basic-auth');
44
const path = require('path');
55
const packageJson = require('package-json');
6+
var fs = require('fs');
67

78
const currentVersionFeatures = require('../package.json').parseDashboardFeatures;
89

@@ -26,6 +27,26 @@ function getMount(req) {
2627
return mountPath;
2728
}
2829

30+
function checkIfIconsExistForApps(apps, iconsFolder) {
31+
for (var i in apps) {
32+
var currentApp = apps[i];
33+
var iconName = currentApp.iconName;
34+
var path = iconsFolder + "/" + iconName;
35+
36+
fs.stat(path, function(err, stat) {
37+
if (err != null && err.code == 'ENOENT') {
38+
// file does not exist
39+
console.warn("Icon with file name: " + iconName +
40+
" couldn't be found in icons folder!");
41+
} else {
42+
console.log(
43+
'An error occurd while checking for icons, please check permission: ',
44+
err.code);
45+
}
46+
});
47+
}
48+
}
49+
2950
module.exports = function(config, allowInsecureHTTP) {
3051
var app = express();
3152
// Serve public files.
@@ -116,7 +137,18 @@ module.exports = function(config, allowInsecureHTTP) {
116137
// We are explicitly not using `__dirpath` here because one may be
117138
// running parse-dashboard from globally installed npm.
118139
if (config.iconsFolder) {
119-
app.use('/appicons', express.static(config.iconsFolder));
140+
try {
141+
var stat = fs.statSync(config.iconsFolder);
142+
if (stat.isDirectory()) {
143+
app.use('/appicons', express.static(config.iconsFolder));
144+
//Check also if the icons really exist
145+
checkIfIconsExistForApps(config.apps, config.iconsFolder);
146+
}
147+
} catch (e) {
148+
// Directory doesn't exist or something.
149+
console.warn("Iconsfolder at path: " + config.iconsFolder +
150+
" not found!");
151+
}
120152
}
121153

122154
// For every other request, go to index.html. Let client-side handle the rest.

Parse-Dashboard/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ p.then(config => {
117117
var fs = require('fs');
118118
var privateKey = fs.readFileSync(configSSLKey);
119119
var certificate = fs.readFileSync(configSSLCert);
120-
120+
121121
const server = require('https').createServer({
122122
key: privateKey,
123123
cert: certificate
@@ -143,6 +143,6 @@ p.then(config => {
143143
}
144144
})
145145
.catch(error => {
146-
console.log('There was a problem loading the dashboard. Exiting.');
146+
console.log('There was a problem loading the dashboard. Exiting.', error);
147147
process.exit(-1);
148148
});
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
2-
"apps": [
3-
4-
]
2+
"apps": [{
3+
"serverURL": "",
4+
"appId": "",
5+
"masterKey": "",
6+
"appName": "",
7+
"iconName": ""
8+
}],
9+
"iconsFolder": "icons"
510
}

0 commit comments

Comments
 (0)