Skip to content

gives the developer feedback if something is wrong with the icons directory #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion Parse-Dashboard/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const express = require('express');
const basicAuth = require('basic-auth');
const path = require('path');
const packageJson = require('package-json');
var fs = require('fs');

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

Expand All @@ -26,6 +27,26 @@ function getMount(req) {
return mountPath;
}

function checkIfIconsExistForApps(apps, iconsFolder) {
for (var i in apps) {
var currentApp = apps[i];
var iconName = currentApp.iconName;
var path = iconsFolder + "/" + iconName;

fs.stat(path, function(err, stat) {
if (err != null && err.code == 'ENOENT') {
// file does not exist
console.warn("Icon with file name: " + iconName +
" couldn't be found in icons folder!");
} else {
console.log(
'An error occurd while checking for icons, please check permission: ',
err.code);
}
});
}
}

module.exports = function(config, allowInsecureHTTP) {
var app = express();
// Serve public files.
Expand Down Expand Up @@ -116,7 +137,18 @@ module.exports = function(config, allowInsecureHTTP) {
// We are explicitly not using `__dirpath` here because one may be
// running parse-dashboard from globally installed npm.
if (config.iconsFolder) {
app.use('/appicons', express.static(config.iconsFolder));
try {
var stat = fs.statSync(config.iconsFolder);
if (stat.isDirectory()) {
app.use('/appicons', express.static(config.iconsFolder));
//Check also if the icons really exist
checkIfIconsExistForApps(config.apps, config.iconsFolder);
}
} catch (e) {
// Directory doesn't exist or something.
console.warn("Iconsfolder at path: " + config.iconsFolder +
" not found!");
}
}

// For every other request, go to index.html. Let client-side handle the rest.
Expand Down
4 changes: 2 additions & 2 deletions Parse-Dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ p.then(config => {
var fs = require('fs');
var privateKey = fs.readFileSync(configSSLKey);
var certificate = fs.readFileSync(configSSLCert);

const server = require('https').createServer({
key: privateKey,
cert: certificate
Expand All @@ -143,6 +143,6 @@ p.then(config => {
}
})
.catch(error => {
console.log('There was a problem loading the dashboard. Exiting.');
console.log('There was a problem loading the dashboard. Exiting.', error);
process.exit(-1);
});
11 changes: 8 additions & 3 deletions Parse-Dashboard/parse-dashboard-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"apps": [

]
"apps": [{
"serverURL": "",
"appId": "",
"masterKey": "",
"appName": "",
"iconName": ""
}],
"iconsFolder": "icons"
}