Skip to content

Commit

Permalink
feat: add workspace with vite project
Browse files Browse the repository at this point in the history
  • Loading branch information
patelmilanun committed Mar 30, 2024
1 parent 931942e commit 6cd29de
Show file tree
Hide file tree
Showing 22 changed files with 27,741 additions and 16,359 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules/
bundles/
PIG/bundles/
Parse-Dashboard/public/bundles/
Parse-Dashboard/v2/
Parse-Dashboard/parse-dashboard-config.json
npm-debug.log
.eslintcache
Expand All @@ -17,3 +18,6 @@ test_logs

# visual studio code
.vscode

.history
.turbo
22 changes: 20 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,25 @@ COPY . /src
# Install remaining dev dependencies
RUN npm ci

# Run all webpack build steps
RUN npm run prepare && npm run build
############################################################
# Build stage v2
############################################################
FROM node:lts-alpine AS v2-build

RUN apk --no-cache add git
WORKDIR /src

# Copy package.json first to benefit from layer caching
COPY v2/package*.json ./

# Install dependencies
RUN npm ci

# Copy src to have webpack config files ready for install
COPY ./v2 ./

# Run build step
RUN npm run build

############################################################
# Release stage
Expand All @@ -36,6 +53,7 @@ COPY --from=build /src/package*.json /src/

# Copy compiled src dirs
COPY --from=build /src/Parse-Dashboard/ /src/Parse-Dashboard/
COPY --from=v2-build /Parse-Dashboard/v2 /src/Parse-Dashboard/v2

USER node

Expand Down
69 changes: 43 additions & 26 deletions Parse-Dashboard/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
console.warn('Icon with file name: ' + iconName + ' couldn\'t be found in icons folder!');
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
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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.');
Expand All @@ -131,7 +142,7 @@ module.exports = function(config, options) {
app.masterKey = app.readOnlyMasterKey;
}
return isSame;
})
});
});
}
// They provided correct auth
Expand Down Expand Up @@ -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'}`);
}
Expand All @@ -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>
Expand All @@ -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) {
Expand All @@ -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" />
Expand All @@ -232,8 +246,11 @@ module.exports = function(config, options) {
</body>
</html>
`);
} else {
next();
}
});
});

return app;
}
};
Loading

0 comments on commit 6cd29de

Please sign in to comment.