Skip to content

feat: Add workspace with vite project for v2 dashboard #2540

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

Draft
wants to merge 20 commits into
base: alpha
Choose a base branch
from
Draft
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
26 changes: 26 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.DS_Store
node_modules/
bundles/
PIG/bundles/
Parse-Dashboard/public/bundles/
Parse-Dashboard/public/v2/
Parse-Dashboard/v2/
Parse-Dashboard/parse-dashboard-config.json
npm-debug.log
.eslintcache

// vim .swp
*.swp
.env
.idea/

logs/
test_logs

# visual studio code
.vscode

.history
.turbo

v2
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ node_modules/
bundles/
PIG/bundles/
Parse-Dashboard/public/bundles/
Parse-Dashboard/public/v2/
Parse-Dashboard/v2/
Parse-Dashboard/parse-dashboard-config.json
npm-debug.log
.eslintcache
@@ -17,3 +19,6 @@ test_logs

# visual studio code
.vscode

.history
.turbo
1 change: 1 addition & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "{src,webpack}/{**/*,*}.js": ["prettier --write", "eslint --fix --cache"] }
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -21,9 +21,6 @@ COPY . /src
# Install remaining dev dependencies
RUN npm ci

# Run all webpack build steps
RUN npm run prepare && npm run build

############################################################
# Release stage
############################################################
67 changes: 42 additions & 25 deletions Parse-Dashboard/app.js
Original file line number Diff line number Diff line change
@@ -36,13 +36,13 @@ function checkIfIconsExistForApps(apps, iconsFolder) {
const iconName = currentApp.iconName;
const path = iconsFolder + '/' + iconName;

fs.stat(path, function(err) {
fs.stat(path, function (err) {
if (err) {
if ('ENOENT' == err.code) {// file does not exist
if ('ENOENT' == err.code) {
// 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!');
console.log('An error occurd while checking for icons, please check permission!');
}
} else {
//every thing was ok so for example you can read it and send it to client
@@ -51,37 +51,42 @@ function checkIfIconsExistForApps(apps, iconsFolder) {
}
}

module.exports = function(config, options) {
module.exports = function (config, options) {
options = options || {};
const app = express();
// Serve public files.
app.use(express.static(path.join(__dirname,'public')));
app.use(express.static(path.join(__dirname, 'public')));

// Allow setting via middleware
if (config.trustProxy && app.disabled('trust proxy')) {
app.enable('trust proxy');
}

// wait for app to mount in order to get mountpath
app.on('mount', function() {
app.on('mount', function () {
const mountPath = getMount(app.mountpath);
const users = config.users;
const useEncryptedPasswords = config.useEncryptedPasswords ? true : false;
const authInstance = new Authentication(users, useEncryptedPasswords, mountPath);
authInstance.initialize(app, { cookieSessionSecret: options.cookieSessionSecret, cookieSessionMaxAge: options.cookieSessionMaxAge });
authInstance.initialize(app, {
cookieSessionSecret: options.cookieSessionSecret,
cookieSessionMaxAge: options.cookieSessionMaxAge,
});

// CSRF error handler
app.use(function (err, req, res, next) {
if (err.code !== 'EBADCSRFTOKEN') {return next(err)}
if (err.code !== 'EBADCSRFTOKEN') {
return next(err);
}

// handle CSRF token errors here
res.status(403)
res.send('form tampered with')
res.status(403);
res.send('form tampered with');
});

// Serve the configuration.
app.get('/parse-dashboard-config.json', function(req, res) {
const apps = config.apps.map((app) => Object.assign({}, app)); // make a copy
app.get('/parse-dashboard-config.json', function (req, res) {
const apps = config.apps.map(app => Object.assign({}, app)); // make a copy
const response = {
apps: apps,
newFeaturesInLatestVersion: newFeaturesInLatestVersion,
@@ -96,12 +101,18 @@ module.exports = function(config, options) {
if (!options.dev && !requestIsLocal) {
if (!req.secure && !options.allowInsecureHTTP) {
//Disallow HTTP requests except on localhost, to prevent the master key from being transmitted in cleartext
return res.send({ success: false, error: 'Parse Dashboard can only be remotely accessed via HTTPS' });
return res.send({
success: false,
error: 'Parse Dashboard can only be remotely accessed via HTTPS',
});
}

if (!users) {
//Accessing the dashboard over the internet can only be done with username and password
return res.send({ success: false, error: 'Configure a user to access Parse Dashboard remotely' });
return res.send({
success: false,
error: 'Configure a user to access Parse Dashboard remotely',
});
}
}
const authentication = req.user;
@@ -111,7 +122,7 @@ module.exports = function(config, options) {
const isReadOnly = authentication && authentication.isReadOnly;
// User is full read-only, replace the masterKey by the read-only one
if (isReadOnly) {
response.apps = response.apps.map((app) => {
response.apps = response.apps.map(app => {
app.masterKey = app.readOnlyMasterKey;
if (!app.masterKey) {
throw new Error('You need to provide a readOnlyMasterKey to use read-only features.');
@@ -131,7 +142,7 @@ module.exports = function(config, options) {
app.masterKey = app.readOnlyMasterKey;
}
return isSame;
})
});
});
}
// They provided correct auth
@@ -167,13 +178,15 @@ module.exports = function(config, options) {
}
} catch (e) {
// Directory doesn't exist or something.
console.warn('Iconsfolder at path: ' + config.iconsFolder +
' not found!');
console.warn('Iconsfolder at path: ' + config.iconsFolder + ' not found!');
}
}

app.get('/login', csrf(), function(req, res) {
const redirectURL = req.url.includes('?redirect=') && req.url.split('?redirect=')[1].length > 1 && req.url.split('?redirect=')[1];
app.get('/login', csrf(), function (req, res) {
const redirectURL =
req.url.includes('?redirect=') &&
req.url.split('?redirect=')[1].length > 1 &&
req.url.split('?redirect=')[1];
if (!users || (req.user && req.user.isAuthenticated)) {
return res.redirect(`${mountPath}${redirectURL || 'apps'}`);
}
@@ -182,7 +195,7 @@ module.exports = function(config, options) {
if (errors && errors.length) {
errors = `<div id="login_errors" style="display: none;">
${errors.join(' ')}
</div>`
</div>`;
}
res.send(`<!DOCTYPE html>
<html>
@@ -205,7 +218,7 @@ module.exports = function(config, options) {
});

// For every other request, go to index.html. Let client-side handle the rest.
app.get('/*', function(req, res) {
app.get('/*', function (req, res, next) {
if (users && (!req.user || !req.user.isAuthenticated)) {
const redirect = req.url.replace('/login', '');
if (redirect.length > 1) {
@@ -216,7 +229,8 @@ module.exports = function(config, options) {
if (users && req.user && req.user.matchingUsername) {
res.append('username', req.user.matchingUsername);
}
res.send(`<!DOCTYPE html>
if (!req.path.startsWith('/v2')) {
res.send(`<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" type="image/x-icon" href="${mountPath}favicon.ico" />
@@ -232,8 +246,11 @@ module.exports = function(config, options) {
</body>
</html>
`);
} else {
next();
}
});
});

return app;
}
};
Loading
Oops, something went wrong.