yads / nodemailer-express-handlebars

A plugin for nodemailer that uses express-handlebars view engine to generate emails
87 stars 30 forks source link

Nodemailer + Handlebars + NextJS - The correct path #32

Closed ghost closed 4 years ago

ghost commented 5 years ago

I'm experiencing problems to find the right path settings in production for my nodemailer/handlebars setup. The transporter is connected to an API request in order to send an automatic email.

In development I'm leaving the configuration as is, so basically I have this situation:

module.exports.ViewOption = (transport, hbs) => {
  transport.use('compile', hbs({
    viewEngine: {
      extname: '.hbs',
      partialsDir: 'static/js/mail/views/email',
      layoutsDir: 'static/js/mail/views',
      defaultLayout: 'contacts'
    },
    viewPath: 'static/js/mail/views',
    extName: '.hbs'
  }));
}

No problems here, everything works fine.

On Now instead, I'm receiving this exception:

e14c1fe1-d069-417f-bb3b-4280cce1193e-Screenshot%202019-11-06%20at%2010 47 57

The request returns an ok response as you can see here:

9b9308ff-40e7-448f-9649-097d2414bd67-Screenshot%202019-11-06%20at%2010 48 10

So I concluded that the problem is related to the wrong path set on transporter config. I can't live it like on dev because it redirects on /var/tasks. The problem is that I've tried different ways to locate the file path correctly, without success:

This is my current filesystem:

3e9a6197-28e3-4044-aff4-861fc2090789-Screenshot%202019-11-06%20at%2010 49 25 9e614c26-ad2d-4fce-a7be-b1f30795e3d3-Screenshot%202019-11-06%20at%2010 48 39

As you can see, I've the config file both inside on /static/js/mail/config than /_next/static/js/mail/config. None of both worked, the call responses every time with the same error, independently by its path.

This is my current now.json if it could be helpful:

{
  "public": false,
  "name": "LC",
  "version": 2,
  "routes": [{
    "src": "/resume",
    "dest": "https://lucacattide.dev/static/html/resume.html"
  }, {
    "src": "/robots.txt",
    "dest": "https://lucacattide.dev/static/robots.txt"
  }, {
    "src": "/sitemap.xml",
    "dest": "https://lucacattide.dev/static/sitemap.xml"
  }, {
    "src": "^/service-worker.js$",
    "dest": "/_next/static/service-worker.js",
    "headers": {
      "cache-control": "public, max-age=43200, immutable",
      "Service-Worker-Allowed": "/"
    }
  }],
  "env": {
    "RECAPTCHA_SECRET_KEY": "@recaptcha",
    "SMTP_SERVICE_HOST": "@smtp_host",
    "SMTP_SERVICE_PORT": "@smtp_port",
    "SMTP_SERVICE_SECURE": "@smtp_secure",
    "SMTP_USER_NAME": "@smtp_name",
    "SMTP_USER_PASSWORD": "@smtp_password",
    "SMTP_LOG_NAME": "@smtp_log"
  },
  "github": {
    "enabled": true,
    "autoAlias": false
  }
}

Anyone experienced this before or could help me in some way?

Thanks in advance

yads commented 4 years ago

It would likely be better to ask this on the express-handlebars github. This module just passes along your configuration.

ghost commented 4 years ago

Here's the cause and the solution: https://github.com/ericf/express-handlebars/issues/269#issuecomment-562529760

It's a workaround, so by my experience I suggest to leave this setup and configuration for a non-nextjs context.

Anyway, thanks @yads for your attention.