AndyJamesN
AndyJamesN

Reputation: 498

Nuxt 3 Server with Pug for email templates

I have created an endpoint with Nuxt 3 Server to send emails.

The email sending part is working great.

The styling of the email templates is done with Pug but I am having a hard time to get the path to the pug templates.

I suspect the issue is that the pug files are not being included in the build process.

When deployed to netlify which runs yarn build I get

"ENOENT: no such file or directory, open '~/views/email/welcome.pug'"

async send(template, subject) {
  // 1) Render HTML based on a pug template
  const html = pug.renderFile(
    `~/views/email/${template}.pug`,
    {
      firstName: this.firstName,
      url: this.url,
      data: this.data,
      subject
    }
  );
}

My project structure looks like this.

enter image description here

What would be the best way to handle this?

Upvotes: 2

Views: 963

Answers (1)

kissu
kissu

Reputation: 46761

Since you want to send emails, you will a Node.js server somewhere. You could use Heroku and push your code there, then use yarn build && yarn start there.

Should fix your issue.

PS: yarn generate is for SSG, Netlify can handle those apps for free but it will not come with all the server capabilities.

Upvotes: 1

Related Questions