From d889bfb525f98bb63a5065a225292612c7885d5a Mon Sep 17 00:00:00 2001 From: Ben Burns Date: Sat, 1 Sep 2018 14:21:47 -0700 Subject: [PATCH 1/4] Fix missing python dependency in docker build --- Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index dc55a5d..9de803e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,11 @@ FROM mhart/alpine-node:8 ENV NODE_VERSION 8.9.4 +RUN apk add --no-cache make gcc g++ python bash + WORKDIR /var/expressCart +COPY lib/ /var/expressCart/lib/ COPY bin/ /var/expressCart/bin/ COPY config/ /var/expressCart/config/ COPY public/ /var/expressCart/public/ @@ -19,4 +22,4 @@ RUN npm install VOLUME /var/expressCart/data EXPOSE 1111 -ENTRYPOINT ["npm", "start"] \ No newline at end of file +ENTRYPOINT ["npm", "start"] From 539261d14045c2a79576f4f5cb86a9b40a03c4c7 Mon Sep 17 00:00:00 2001 From: Ben Burns Date: Sat, 1 Sep 2018 16:22:42 -0700 Subject: [PATCH 2/4] Rename mongodb container to expresscart-mongodb This change avoids naming conflicts with other mongodb containers. --- docker-compose.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1aedb15..a3302a0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,13 +15,13 @@ services: - mongodb mongodb: image: mongo:3.4.10 - container_name: "mongodb" + container_name: "expresscart-mongodb" ports: - 27017 volumes: - - mongo-data:/data/db + - expresscart-mongo-data:/data/db ports: - 27017:27017 command: mongod --smallfiles --logpath=/dev/null volumes: - mongo-data: \ No newline at end of file + expresscart-mongo-data: From 70127ee0bc1ac093a5d250d88da9c3574f27e8b9 Mon Sep 17 00:00:00 2001 From: Ben Burns Date: Sat, 1 Sep 2018 16:08:11 -0700 Subject: [PATCH 3/4] Allow for an ignored local settings file. Even though settings.json is in the .gitignore file git does not ignore modifications to this file. This change makes expressCart detect the existence of a file called settings-local.json. When this file exists, it will be used for reading and writing settings instead of the usual settings.json. This will help to prevent accidental leakage of user secrets. --- .gitignore | 4 ++-- README.md | 8 +++++++- lib/common.js | 15 ++++++++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 2b761f2..e392609 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ node_modules/ data/ -config/settings.json +/config/settings-local.json .vscode -**.DS_Store \ No newline at end of file +**.DS_Store diff --git a/README.md b/README.md index f73dd0a..c9460b3 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,13 @@ Note: The `databaseConnectionString` property requires a full connection string. ## Configuration -All settings are managed from the admin panel ([http://127.0.0.1:1111/admin](http://127.0.0.1:1111/admin)) except the Payment gateway and database settings. +Settings can be managed from the admin panel ([http://127.0.0.1:1111/admin](http://127.0.0.1:1111/admin)) with the exception of the Payment gateway and database settings. + +All settings are stored in json files in the `/config` directory. The main application-level settings are stored in `/config/settings.json` while payment gateway settings are stored in files in the `/config` directory named after the payment gateway. For example, configuration for the Stripe payment gateway is stored in `/config/stripe.json`. + +##### Local configuration + +If you'd rather store settings in a file which isn't checked into version control, you can create a new settings file at `/config/settings-local.json` and store your complete settings there. When viewing or editing settings in the admin panel, expressCart will detect the existence of this file and update it accordingly. ##### Cart name and Cart description diff --git a/lib/common.js b/lib/common.js index 5e48c15..31f6062 100644 --- a/lib/common.js +++ b/lib/common.js @@ -210,8 +210,17 @@ exports.getImages = (dir, req, res, callback) => { }); }; +exports.getConfigFilename = () => { + let filename = path.join(__dirname, '../config', 'settings-local.json'); + if (fs.existsSync(filename)) { + return filename; + } else { + return path.join(__dirname, '../config', 'settings.json'); + } +}; + exports.getConfig = () => { - let config = JSON.parse(fs.readFileSync(path.join(__dirname, '../config', 'settings.json'), 'utf8')); + let config = JSON.parse(fs.readFileSync(exports.getConfigFilename(), 'utf8')); config.customCss = typeof config.customCss !== 'undefined' ? escape.decode(config.customCss) : null; config.footerHtml = typeof config.footerHtml !== 'undefined' ? escape.decode(config.footerHtml) : null; config.googleAnalytics = typeof config.googleAnalytics !== 'undefined' ? escape.decode(config.googleAnalytics) : null; @@ -248,7 +257,7 @@ exports.getPaymentConfig = () => { }; exports.updateConfig = (fields) => { - let settingsFile = JSON.parse(fs.readFileSync(path.join(__dirname, '../config/settings.json'), 'utf8')); + let settingsFile = exports.getConfig(); _.forEach(fields, (value, key) => { settingsFile[key] = value; @@ -304,7 +313,7 @@ exports.updateConfig = (fields) => { // write file try{ - fs.writeFileSync(path.join(__dirname, '../config/settings.json'), JSON.stringify(settingsFile, null, 4)); + fs.writeFileSync(exports.getConfigFilename(), JSON.stringify(settingsFile, null, 4)); return true; }catch(exception){ return false; From 9b0f7a03b71f9fc5259f7ef9159725d9841b20a2 Mon Sep 17 00:00:00 2001 From: Ben Burns Date: Sat, 1 Sep 2018 15:48:29 -0700 Subject: [PATCH 4/4] Handle settings changes without restart Prior to this change, edited settings on the /admin/settings page required a restart for the edit to take effect. This even causes the settings page itself to not reflect the updated settings once you navigate away from it or refresh. This change triggers the config to reload when the settings are modified, which causes the impacted templates to be recomputed. --- app.js | 9 +++++++++ routes/admin.js | 1 + 2 files changed, 10 insertions(+) diff --git a/app.js b/app.js index d831e44..815f28d 100644 --- a/app.js +++ b/app.js @@ -249,6 +249,15 @@ app.use((req, res, next) => { next(); }); +// update config when modified +app.use((req, res, next) => { + next(); + if (res.configDirty) { + config = common.getConfig(); + app.config = config; + } +}); + // Ran on all routes app.use((req, res, next) => { res.setHeader('Cache-Control', 'no-cache, no-store'); diff --git a/routes/admin.js b/routes/admin.js index d487bbb..6fedb4b 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -171,6 +171,7 @@ router.post('/admin/settings/update', common.restrict, common.checkAccess, (req, let result = common.updateConfig(req.body); if(result === true){ res.status(200).json({message: 'Settings successfully updated'}); + res.configDirty = true; return; } res.status(400).json({message: 'Permission denied'});