mjml-server
mjml-server copied to clipboard
Behaves differently
Input:
POST http://localhost:25800/v1/render
{"mjml":"<mjml><mj-text font-size=\"16px\">Test</mj-text></mjml>\n"}
Response:
HTTP/1.1 400 Bad Request
X-Powered-By: Express
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: *
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: -1
Content-Type: text/plain
Date: Sun, 31 Jul 2022 11:29:36 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Transfer-Encoding: chunked
ValidationError:
Line undefined of undefined (undefined) â Element undefined doesn't exist or is not registered
In the logs:
{}
2022-07-31T11:30:32.035123500Z ValidationError: ValidationError:
2022-07-31T11:30:32.035153200Z Line undefined of undefined (undefined) — Element undefined doesn't exist or is not registered
2022-07-31T11:30:32.035161400Z at mjml2html (/app/node_modules/mjml-core/lib/index.js:271:15)
2022-07-31T11:30:32.035167200Z at /app/index.js:50:24
2022-07-31T11:30:32.035171900Z at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2022-07-31T11:30:32.035176200Z at next (/app/node_modules/express/lib/router/route.js:144:13)
2022-07-31T11:30:32.035180100Z at next (/app/node_modules/express/lib/router/route.js:138:14)
2022-07-31T11:30:32.035184300Z at next (/app/node_modules/express/lib/router/route.js:138:14)
2022-07-31T11:30:32.035253100Z at next (/app/node_modules/express/lib/router/route.js:138:14)
2022-07-31T11:30:32.035259800Z at next (/app/node_modules/express/lib/router/route.js:138:14)
2022-07-31T11:30:32.035263900Z at next (/app/node_modules/express/lib/router/route.js:138:14)
2022-07-31T11:30:32.035268000Z at next (/app/node_modules/express/lib/router/route.js:138:14) {
2022-07-31T11:30:32.035272200Z errors: [
2022-07-31T11:30:32.035276100Z {
2022-07-31T11:30:32.035280000Z line: undefined,
2022-07-31T11:30:32.035283800Z message: "Element undefined doesn't exist or is not registered",
2022-07-31T11:30:32.035288200Z tagName: undefined,
2022-07-31T11:30:32.035292400Z formattedMessage: "Line undefined of undefined (undefined) — Element undefined doesn't exist or is not registered"
2022-07-31T11:30:32.035296600Z }
2022-07-31T11:30:32.035299800Z ]
2022-07-31T11:30:32.035303200Z }
Sending the exact same request to https://api.mjml.io/v1/render:
HTTP/1.1 200 OK
content-length: 1657
content-type: application/json; charset=UTF-8
x-mj-request-guid: ee3577f9-9b08-4d80-a45c-f22980448e6a
date: Sun, 31 Jul 2022 11:57:02 GMT
{
"html": "\n <!doctype html>\n <html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\">\n <head>\n <title>\n \n </title>\n <!--[if !mso]><!-- -->\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n <!--<![endif]-->\n <meta http-equiv=\"Content-Type\" contenttext/html; charset=UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <style type=\"text/css\">\n #outlook a { padding:0; }\n body { margin:0;padding:0;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%; }\n table, td { border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt; }\n img { border:0;height:auto;line-height:100%; outline:none;text-decoration:none;-ms-interpolation-mode:bicubic; }\n p { display:block;margin:13px 0; }\n </style>\n <!--[if mso]>\n <xml>\n <o:OfficeDocumentSettings>\n <o:AllowPNG/>\n <o:PixelsPerInch>96</o:PixelsPerInch>\n </o:OfficeDocumentSettings>\n </xml>\n <![endif]-->\n <!--[if lte mso 11]>\n <style type=\"text/css\">\n .mj-outlook-group-fix { width:100% !important; }\n </style>\n <![endif]-->\n \n \n <style type=\"text/css\">\n \n \n </style>\n \n \n </head>\n <body>\n \n \n </body>\n </html>\n ",
"errors": [],
"mjml": "<mjml><mj-text font-size=\"16px\">Test</mj-text></mjml>",
"mjml_version": "4.6.1"
}
Other than that, I had various strange validation errors I'm not able to reproduce right now, which also works with the official API.
Do you use the x64 docker image, or the arm variant? I'll take a look tomorrow and upgrade the mjml_version to the next available minor version.
Sorry I didn't say; I used adrianrudnik/mjml-server:latest x64, that's sha256:d8cfac46ea3ae6e109ce8bb32c11bcc8e354d0475958a8daa3f5f054432722c6
Sorry for the delay, just found a spot to look at this in detail. Is there any reason why you send in JSON? The server accepts just the plain MJML as POST body, i.e.
POST http://localhost:8080/
Content-Type: text/html
<mjml><mj-body><mj-text font-size="16px">Test</mj-text></mj-body></mjml>
based on your example (and added mjml-body tag which is not optional).
Here is the same call as cURL
curl -X POST --location "http://localhost:8080" \
-H "Content-Type: text/html" \
-d "<mjml><mj-body><mj-text font-size=\"16px\">Test</mj-text></mj-body></mjml>"
I see.
I use one of the two Java libraries listed on https://mjml.io/community but I understand now that this project isn't meant to be a drop-in replacement for the official MJML API? :) If it aims to be, I guess it needs to support JSON.