Mailtrain-org / mailtrain

Self hosted newsletter app
GNU General Public License v3.0
5.52k stars 692 forks source link

GrapeJS + Mailtrain behind Apache proxy #189

Closed tehsYs closed 7 years ago

tehsYs commented 7 years ago

Hi there,

It seems like a ran into another issue.

I'm running Mailtrain behind an Apache proxy on two separate virtual machines. When I try to create a campaign in GrapeJS everything seems to be working fine but once a I press save on the GrapeJS UI I get the following error in the mailtrain log and my edits won't get saved:

Apr 4 17:30:41 mailtrain node[4292]: (node:4292) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 5): FetchError: request to http://mailtrain.muranyi.hu/editorapi/img?src=%2Fgrapejs%2Ftemplates%2Fdemo%2Fimages%2Fgrapesjs-logo.png&method=resize&params=67%2C67 failed, reason: connect ECONNREFUSED 10.0.1.108:80 Apr 4 17:30:41 mailtrain node[4292]: (node:4292) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 6): FetchError: request to http://mailtrain.muranyi.hu/editorapi/img?src=%2Fgrapejs%2Ftemplates%2Fdemo%2Fimages%2F550x250.png&method=resize&params=520%2C236 failed, reason: connect ECONNREFUSED 10.0.1.108:80 Apr 4 17:30:41 mailtrain node[4292]: (node:4292) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 7): FetchError: request to http://mailtrain.muranyi.hu/editorapi/img?src=%2Fgrapejs%2Ftemplates%2Fdemo%2Fimages%2F150x150.png&method=resize&params=156%2C156 failed, reason: connect ECONNREFUSED 10.0.1.108:80 Apr 4 17:30:41 mailtrain node[4292]: (node:4292) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 8): FetchError: request to http://mailtrain.muranyi.hu/editorapi/img?src=%2Fgrapejs%2Ftemplates%2Fdemo%2Fimages%2F250x150.png&method=resize&params=249%2C149 failed, reason: connect ECONNREFUSED 10.0.1.108:80

It seems like it tries to connect on the wrong port (80), it probably thinks that is the right port because of the apache proxy, while my mailtrain is running on port 3000. 10.0.1.108 is the internal IP of the virtual machine where mailtrain is running.

My Apache proxy settings are the following:

<VirtualHost *:80> ProxyPreserveHost On ProxyPass "/" "http://10.0.1.108:3000/" ProxyPassReverse "/" "http://10.0.1.108:3000/" ServerName mailtrain.muranyi.hu

witzig commented 7 years ago

It might be imagemagick. Is it installed?

tehsYs commented 7 years ago

Thank you for the insanely fast answer! Imagemagick wasn't installed, I installed it, restarted mailtrain but the error still persists.

witzig commented 7 years ago

https://github.com/Mailtrain-org/mailtrain/blob/master/routes/editorapi.js#L98 Perhaps the token is already gone when the request hits the api. Could you test with a higher value, let's say 10 seconds?

tehsYs commented 7 years ago

Tested it, unfortunately did not help the issue.

I'd like to point out the 'ECONNREFUSED 10.0.1.108:80' part of the error log, it tries to connect to a completely wrong port, it should be either 10.1.1.108:3000 (internal mailtrian port) or 185.43.205.95:80 (the apache proxy port).

witzig commented 7 years ago

When you're logged in, does this link work for you? http://mailtrain.muranyi.hu/editorapi/img?src=%2Fgrapejs%2Ftemplates%2Fdemo%2Fimages%2Fgrapesjs-logo.png&method=resize&params=67%2C67

tehsYs commented 7 years ago

I get the following error:

Command failed: error : Operation in progress identify: improper image header /tmp/magick-220610A0x_QyzayEJ' @ error/png.c/ReadPNGImage/3930. identify: no data returnedhttp://mailtrain.muranyi.hu/grapejs/templates/demo/images/grapesjs-logo.png' @ error/url.c/ReadURLImage/263.

witzig commented 7 years ago

This one? http://mailtrain.muranyi.hu/editorapi/img?src=%2Fmosaico%2Ftemplates%2Fversafix-1%2Fimg%2Fsponsor.gif&method=resize&params=67%2C67

tehsYs commented 7 years ago

Same error: Command failed: error : Operation in progress identify: improper image header /tmp/magick-22867JaIo6p7QgwPP' @ error/gif.c/ReadGIFImage/1037. identify: no data returnedhttp://mailtrain.muranyi.hu/mosaico/templates/versafix-1/img/sponsor.gif' @ error/url.c/ReadURLImage/263.

Interestingly when I remove every image from the campaign I can save it, I'm testing it with the included demo grapejs template.

My imagemagick version is 6.8.9.9-5+deb8u8.

witzig commented 7 years ago

Interestingly when I remove every image from the campaign I can save it, I'm testing it with the included demo grapejs template.

Makes sense. When saving, the editorapi generates resized versions of all images.

If the image url is not absolute, the serviceUrl will be added here https://github.com/Mailtrain-org/mailtrain/blob/master/routes/editorapi.js#L267 then imageMagick reads the file from the url here: https://github.com/Mailtrain-org/mailtrain/blob/master/routes/editorapi.js#L211

Perhaps we could narrow it down if you try with an external image url in GrapeJS. Can imageMagick read that?

tehsYs commented 7 years ago

I tried with https://www.muranyi.hu/wp-content/uploads/sites/5/2016/12/jiol.jpg

Apr 4 18:42:41 mailtrain node[22803]: (node:22803) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 10): FetchError: request to http://mailtrain.muranyi.hu/editorapi/img?src=https%3A%2F%2Fwww.muranyi.hu%2Fwp-content%2Fuploads%2Fsites%2F5%2F2016%2F12%2Fjiol.jpg&method=resize&params=732%2C921 failed, reason: connect ECONNREFUSED 10.0.1.108:80

When I try to open the link in the error message I get: Command failed: identify: not authorized `//www.muranyi.hu/wp-content/uploads/sites/5/2016/12/jiol.jpg' @ error/constitute.c/ReadImage/412.

tehsYs commented 7 years ago

When I try a http url instead of https I get:

http://mailtrain.muranyi.hu/editorapi/img?src=http%3A%2F%2Fmailtrain.muranyi.hu%2Fmailtrain-header.png&method=resize&params=252%2C72

Command failed: error : Operation in progress identify: improper image header /tmp/magick-22919l6RGEvR5B5mB' @ error/png.c/ReadPNGImage/3930. identify: no data returnedhttp://mailtrain.muranyi.hu/mailtrain-header.png' @ error/url.c/ReadURLImage/263.

witzig commented 7 years ago

Can you contact me via email? git.witzig@icloud.com

tehsYs commented 7 years ago

Okey we managed to figure this out, nothing wrong with mailtrain (again). Thank you for your help and sorry for wasting your time.

Long story short: I had mailtrain.muranyi.hu in my /etc/hosts file because this was also the name of the virtual machine(OpenVZ adds this automatically) I was running on it. And while 'dig' and 'host' commands ignore this file, curl, wget and apparently nodejs doesn't. Interestingly everything was working fine this way, the problem appeared only when I tried to use GrapeJS.