Merge branch 'master' of https://github.com/mrvautin/expressCart
commit
dbb3a15f65
|
@ -1,5 +1,5 @@
|
||||||
node_modules/
|
node_modules/
|
||||||
data/
|
data/
|
||||||
config/settings.json
|
/config/settings-local.json
|
||||||
.vscode
|
.vscode
|
||||||
**.DS_Store
|
**.DS_Store
|
||||||
|
|
|
@ -2,8 +2,11 @@ FROM mhart/alpine-node:8
|
||||||
|
|
||||||
ENV NODE_VERSION 8.9.4
|
ENV NODE_VERSION 8.9.4
|
||||||
|
|
||||||
|
RUN apk add --no-cache make gcc g++ python bash
|
||||||
|
|
||||||
WORKDIR /var/expressCart
|
WORKDIR /var/expressCart
|
||||||
|
|
||||||
|
COPY lib/ /var/expressCart/lib/
|
||||||
COPY bin/ /var/expressCart/bin/
|
COPY bin/ /var/expressCart/bin/
|
||||||
COPY config/ /var/expressCart/config/
|
COPY config/ /var/expressCart/config/
|
||||||
COPY public/ /var/expressCart/public/
|
COPY public/ /var/expressCart/public/
|
||||||
|
@ -19,4 +22,4 @@ RUN npm install
|
||||||
VOLUME /var/expressCart/data
|
VOLUME /var/expressCart/data
|
||||||
|
|
||||||
EXPOSE 1111
|
EXPOSE 1111
|
||||||
ENTRYPOINT ["npm", "start"]
|
ENTRYPOINT ["npm", "start"]
|
||||||
|
|
|
@ -122,7 +122,13 @@ Note: The `databaseConnectionString` property requires a full connection string.
|
||||||
|
|
||||||
## Configuration
|
## 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
|
##### Cart name and Cart description
|
||||||
|
|
||||||
|
|
9
app.js
9
app.js
|
@ -249,6 +249,15 @@ app.use((req, res, next) => {
|
||||||
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
|
// Ran on all routes
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
res.setHeader('Cache-Control', 'no-cache, no-store');
|
res.setHeader('Cache-Control', 'no-cache, no-store');
|
||||||
|
|
|
@ -15,13 +15,13 @@ services:
|
||||||
- mongodb
|
- mongodb
|
||||||
mongodb:
|
mongodb:
|
||||||
image: mongo:3.4.10
|
image: mongo:3.4.10
|
||||||
container_name: "mongodb"
|
container_name: "expresscart-mongodb"
|
||||||
ports:
|
ports:
|
||||||
- 27017
|
- 27017
|
||||||
volumes:
|
volumes:
|
||||||
- mongo-data:/data/db
|
- expresscart-mongo-data:/data/db
|
||||||
ports:
|
ports:
|
||||||
- 27017:27017
|
- 27017:27017
|
||||||
command: mongod --smallfiles --logpath=/dev/null
|
command: mongod --smallfiles --logpath=/dev/null
|
||||||
volumes:
|
volumes:
|
||||||
mongo-data:
|
expresscart-mongo-data:
|
||||||
|
|
|
@ -217,8 +217,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 = () => {
|
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.customCss = typeof config.customCss !== 'undefined' ? escape.decode(config.customCss) : null;
|
||||||
config.footerHtml = typeof config.footerHtml !== 'undefined' ? escape.decode(config.footerHtml) : null;
|
config.footerHtml = typeof config.footerHtml !== 'undefined' ? escape.decode(config.footerHtml) : null;
|
||||||
config.googleAnalytics = typeof config.googleAnalytics !== 'undefined' ? escape.decode(config.googleAnalytics) : null;
|
config.googleAnalytics = typeof config.googleAnalytics !== 'undefined' ? escape.decode(config.googleAnalytics) : null;
|
||||||
|
@ -255,7 +264,7 @@ exports.getPaymentConfig = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.updateConfig = (fields) => {
|
exports.updateConfig = (fields) => {
|
||||||
let settingsFile = JSON.parse(fs.readFileSync(path.join(__dirname, '../config/settings.json'), 'utf8'));
|
let settingsFile = exports.getConfig();
|
||||||
|
|
||||||
_.forEach(fields, (value, key) => {
|
_.forEach(fields, (value, key) => {
|
||||||
settingsFile[key] = value;
|
settingsFile[key] = value;
|
||||||
|
@ -311,7 +320,7 @@ exports.updateConfig = (fields) => {
|
||||||
|
|
||||||
// write file
|
// write file
|
||||||
try{
|
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;
|
return true;
|
||||||
}catch(exception){
|
}catch(exception){
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -171,6 +171,7 @@ router.post('/admin/settings/update', common.restrict, common.checkAccess, (req,
|
||||||
let result = common.updateConfig(req.body);
|
let result = common.updateConfig(req.body);
|
||||||
if(result === true){
|
if(result === true){
|
||||||
res.status(200).json({message: 'Settings successfully updated'});
|
res.status(200).json({message: 'Settings successfully updated'});
|
||||||
|
res.configDirty = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
res.status(400).json({message: 'Permission denied'});
|
res.status(400).json({message: 'Permission denied'});
|
||||||
|
|
Loading…
Reference in New Issue