Some fixes in expection logging, template files and resizing mosaico images
This commit is contained in:
parent
63cfb22025
commit
3b20ac5ce7
5 changed files with 43 additions and 79 deletions
|
@ -82,6 +82,12 @@ class MosaicoSandbox extends Component {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Custom convertedUrl (https://github.com/voidlabs/mosaico/blob/a359e263f1af5cf05e2c2d56c771732f2ef6c8c6/src/js/app.js#L42)
|
||||||
|
// which does not complain about mismatch of domains between TRUSTED and PUBLIC
|
||||||
|
plugins.push(viewModel => {
|
||||||
|
ko.bindingHandlers.wysiwygSrc.convertedUrl = (src, method, width, height) => getTrustedUrl(`mosaico/img?src=${encodeURIComponent(src)}&method=${encodeURIComponent(method)}¶ms=${width},${height}`);
|
||||||
|
});
|
||||||
|
|
||||||
plugins.unshift(vm => {
|
plugins.unshift(vm => {
|
||||||
// This is an override of the default paths in Mosaico
|
// This is an override of the default paths in Mosaico
|
||||||
vm.logoPath = getTrustedUrl('static/mosaico/img/mosaico32.png');
|
vm.logoPath = getTrustedUrl('static/mosaico/img/mosaico32.png');
|
||||||
|
|
|
@ -320,93 +320,49 @@ function createApp(appType) {
|
||||||
|
|
||||||
app.use('/', index.getRouter(appType));
|
app.use('/', index.getRouter(appType));
|
||||||
|
|
||||||
// Error handlers
|
app.use((err, req, res, next) => {
|
||||||
if (app.get('env') === 'development' || app.get('env') === 'test') {
|
if (!err) {
|
||||||
// development error handler
|
return next();
|
||||||
// will print stacktrace
|
}
|
||||||
app.use((err, req, res, next) => {
|
|
||||||
if (!err) {
|
if (req.needsRESTJSONResponse) {
|
||||||
return next();
|
const resp = {
|
||||||
|
message: err.message,
|
||||||
|
error: config.sendStacktracesToClient ? err : {}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (err instanceof interoperableErrors.InteroperableError) {
|
||||||
|
resp.type = err.type;
|
||||||
|
resp.data = err.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.needsRESTJSONResponse) {
|
log.verbose('HTTP', err);
|
||||||
const resp = {
|
res.status(err.status || 500).json(resp);
|
||||||
message: err.message,
|
|
||||||
error: err
|
|
||||||
};
|
|
||||||
|
|
||||||
if (err instanceof interoperableErrors.InteroperableError) {
|
} else if (req.needsAPIJSONResponse) {
|
||||||
resp.type = err.type;
|
const resp = {
|
||||||
resp.data = err.data;
|
error: err.message || err,
|
||||||
}
|
data: []
|
||||||
|
};
|
||||||
|
|
||||||
res.status(err.status || 500).json(resp);
|
log.verbose('HTTP', err);
|
||||||
|
return res.status(err.status || 500).json(resp);
|
||||||
|
|
||||||
} else if (req.needsAPIJSONResponse) {
|
} else {
|
||||||
const resp = {
|
// TODO: Render interoperable errors using a special client that does internationalization of the error message
|
||||||
error: err.message || err,
|
|
||||||
data: []
|
|
||||||
};
|
|
||||||
|
|
||||||
return status(err.status || 500).json(resp);
|
|
||||||
|
|
||||||
|
if (err instanceof interoperableErrors.NotLoggedInError) {
|
||||||
|
return res.redirect(getTrustedUrl('/login?next=' + encodeURIComponent(req.originalUrl)));
|
||||||
} else {
|
} else {
|
||||||
if (err instanceof interoperableErrors.NotLoggedInError) {
|
log.verbose('HTTP', err);
|
||||||
return res.redirect(getTrustedUrl('/login?next=' + encodeURIComponent(req.originalUrl)));
|
res.status(err.status || 500);
|
||||||
} else {
|
res.render('error', {
|
||||||
res.status(err.status || 500);
|
|
||||||
res.render('error', {
|
|
||||||
message: err.message,
|
|
||||||
error: err
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// production error handler
|
|
||||||
// no stacktraces leaked to user
|
|
||||||
app.use((err, req, res, next) => {
|
|
||||||
if (!err) {
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.needsRESTJSONResponse) {
|
|
||||||
const resp = {
|
|
||||||
message: err.message,
|
message: err.message,
|
||||||
error: {}
|
error: config.sendStacktracesToClient ? err : {}
|
||||||
};
|
});
|
||||||
|
|
||||||
if (err instanceof interoperableErrors.InteroperableError) {
|
|
||||||
resp.type = err.type;
|
|
||||||
resp.data = err.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
res.status(err.status || 500).json(resp);
|
|
||||||
|
|
||||||
} else if (req.needsAPIJSONResponse) {
|
|
||||||
const resp = {
|
|
||||||
error: err.message || err,
|
|
||||||
data: []
|
|
||||||
};
|
|
||||||
|
|
||||||
return res.status(err.status || 500).json(resp);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// TODO: Render interoperable errors using a special client that does internationalization of the error message
|
|
||||||
|
|
||||||
if (err instanceof interoperableErrors.NotLoggedInError) {
|
|
||||||
return res.redirect(getTrustedUrl('/login?next=' + encodeURIComponent(req.originalUrl)));
|
|
||||||
} else {
|
|
||||||
res.status(err.status || 500);
|
|
||||||
res.render('error', {
|
|
||||||
message: err.message,
|
|
||||||
error: {}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ redis:
|
||||||
log:
|
log:
|
||||||
# silly|verbose|info|http|warn|error|silent
|
# silly|verbose|info|http|warn|error|silent
|
||||||
level: info
|
level: info
|
||||||
|
sendStacktracesToClient: false
|
||||||
|
|
||||||
www:
|
www:
|
||||||
# HTTP port to listen on for trusted requests (logged-in users)
|
# HTTP port to listen on for trusted requests (logged-in users)
|
||||||
|
|
|
@ -24,6 +24,7 @@ const { AppType } = require('../shared/app');
|
||||||
const builtinZoneMta = require('./lib/builtin-zone-mta');
|
const builtinZoneMta = require('./lib/builtin-zone-mta');
|
||||||
|
|
||||||
const { uploadedFilesDir } = require('./lib/file-helpers');
|
const { uploadedFilesDir } = require('./lib/file-helpers');
|
||||||
|
const { filesDir } = require('./models/files');
|
||||||
|
|
||||||
const trustedPort = config.www.trustedPort;
|
const trustedPort = config.www.trustedPort;
|
||||||
const sandboxPort = config.www.sandboxPort;
|
const sandboxPort = config.www.sandboxPort;
|
||||||
|
@ -113,6 +114,7 @@ dbcheck(err => { // Check if database needs upgrading before starting the server
|
||||||
startHTTPServer(AppType.SANDBOXED, 'sandbox', sandboxPort, () =>
|
startHTTPServer(AppType.SANDBOXED, 'sandbox', sandboxPort, () =>
|
||||||
startHTTPServer(AppType.PUBLIC, 'public', publicPort, async () => {
|
startHTTPServer(AppType.PUBLIC, 'public', publicPort, async () => {
|
||||||
|
|
||||||
|
await privilegeHelpers.ensureMailtrainDir(filesDir);
|
||||||
await privilegeHelpers.ensureMailtrainDir(uploadedFilesDir);
|
await privilegeHelpers.ensureMailtrainDir(uploadedFilesDir);
|
||||||
|
|
||||||
privilegeHelpers.dropRootPrivileges();
|
privilegeHelpers.dropRootPrivileges();
|
||||||
|
|
|
@ -156,7 +156,6 @@ function getRouter(appType) {
|
||||||
// This is a fallback to versafix-1 if the block thumbnail is not defined by the template
|
// This is a fallback to versafix-1 if the block thumbnail is not defined by the template
|
||||||
router.use('/templates/:mosaicoTemplateId/edres', express.static(path.join(__dirname, '..', '..', 'client', 'static', 'mosaico', 'templates', 'versafix-1', 'edres')));
|
router.use('/templates/:mosaicoTemplateId/edres', express.static(path.join(__dirname, '..', '..', 'client', 'static', 'mosaico', 'templates', 'versafix-1', 'edres')));
|
||||||
|
|
||||||
|
|
||||||
fileHelpers.installUploadHandler(router, '/upload/:type/:entityId', files.ReplacementBehavior.RENAME, null, 'file', resp => {
|
fileHelpers.installUploadHandler(router, '/upload/:type/:entityId', files.ReplacementBehavior.RENAME, null, 'file', resp => {
|
||||||
return {
|
return {
|
||||||
files: resp.files.map(f => ({name: f.name, url: f.url, size: f.size, thumbnailUrl: f.thumbnailUrl}))
|
files: resp.files.map(f => ({name: f.name, url: f.url, size: f.size, thumbnailUrl: f.thumbnailUrl}))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue