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 => {
|
||||
// This is an override of the default paths in Mosaico
|
||||
vm.logoPath = getTrustedUrl('static/mosaico/img/mosaico32.png');
|
||||
|
|
|
@ -320,10 +320,6 @@ function createApp(appType) {
|
|||
|
||||
app.use('/', index.getRouter(appType));
|
||||
|
||||
// Error handlers
|
||||
if (app.get('env') === 'development' || app.get('env') === 'test') {
|
||||
// development error handler
|
||||
// will print stacktrace
|
||||
app.use((err, req, res, next) => {
|
||||
if (!err) {
|
||||
return next();
|
||||
|
@ -332,49 +328,7 @@ function createApp(appType) {
|
|||
if (req.needsRESTJSONResponse) {
|
||||
const resp = {
|
||||
message: err.message,
|
||||
error: 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 status(err.status || 500).json(resp);
|
||||
|
||||
} else {
|
||||
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: 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,
|
||||
error: {}
|
||||
error: config.sendStacktracesToClient ? err : {}
|
||||
};
|
||||
|
||||
if (err instanceof interoperableErrors.InteroperableError) {
|
||||
|
@ -382,6 +336,7 @@ function createApp(appType) {
|
|||
resp.data = err.data;
|
||||
}
|
||||
|
||||
log.verbose('HTTP', err);
|
||||
res.status(err.status || 500).json(resp);
|
||||
|
||||
} else if (req.needsAPIJSONResponse) {
|
||||
|
@ -390,6 +345,7 @@ function createApp(appType) {
|
|||
data: []
|
||||
};
|
||||
|
||||
log.verbose('HTTP', err);
|
||||
return res.status(err.status || 500).json(resp);
|
||||
|
||||
} else {
|
||||
|
@ -398,15 +354,15 @@ function createApp(appType) {
|
|||
if (err instanceof interoperableErrors.NotLoggedInError) {
|
||||
return res.redirect(getTrustedUrl('/login?next=' + encodeURIComponent(req.originalUrl)));
|
||||
} else {
|
||||
log.verbose('HTTP', err);
|
||||
res.status(err.status || 500);
|
||||
res.render('error', {
|
||||
message: err.message,
|
||||
error: {}
|
||||
error: config.sendStacktracesToClient ? err : {}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return app;
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ redis:
|
|||
log:
|
||||
# silly|verbose|info|http|warn|error|silent
|
||||
level: info
|
||||
sendStacktracesToClient: false
|
||||
|
||||
www:
|
||||
# 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 { uploadedFilesDir } = require('./lib/file-helpers');
|
||||
const { filesDir } = require('./models/files');
|
||||
|
||||
const trustedPort = config.www.trustedPort;
|
||||
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.PUBLIC, 'public', publicPort, async () => {
|
||||
|
||||
await privilegeHelpers.ensureMailtrainDir(filesDir);
|
||||
await privilegeHelpers.ensureMailtrainDir(uploadedFilesDir);
|
||||
|
||||
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
|
||||
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 => {
|
||||
return {
|
||||
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