dword-design / nuxt-mail

Adds email sending capability to a Nuxt.js app. Adds a server route, an injected variable, and uses nodemailer to send emails.
Other
247 stars 18 forks source link

404 Error with builded site #69

Closed AndreyPividori closed 3 years ago

AndreyPividori commented 3 years ago

Hello,

I'm new to development and trying to do my own projects. I am currently working on a project in which I am making a form that would allow people to contact me and so I decided to use Nuxt-mail.

The latter works very well when working locally but I encountered problems when building the project. I first updated the "baseURL" variable of the axios module to tell it if I was working locally or in production with the domain name I am using today :

// Nuxt.config.js
axios: {
    baseURL: process.env.NODE_ENV === 'dev'
      ? 'http://localhost:3000'
      : 'https://my-domain.netlify.app'
  },

Everything works fine during the 'localhost: 3000 / mail / send' request but I get a 404 error when requesting from my host: 'https://my-domain.netlify.app/mail/send'.

I have the following error :

POST https://my-domain.netlify.app/mail/send                    [HTTP/2 404 Not Found 186ms]
Uncaught (in promise) Error: Request failed with status code 404

I tryed to request it from Postman and I got the same error.

Am I missing something using Nuxt-mail or is it something more global in my project ?

dword-design commented 3 years ago

@AndreyPividori Hey, I can't find an error at first sight. Are you sure that the env logic works on production? So does it actually take the https://my-domain.netlify.app url? Maybe add a console.log in nuxt.config.js, start, and see if it's the correct one?

AndreyPividori commented 3 years ago

@dword-design I made sure the link I used is my website link, already added a console.log to check it out. If you want to make sure yourself you can test directly here: netlify-website by clicking the green button. I juste noticed that when I work locally I'm using http://localhost and on production it's https://my-domain. I'm struggling to solve this problem actually 🤔

dword-design commented 3 years ago

@AndreyPividori Hey, sorry for the late reply. The website you linked seems to be offline. Any news on this? I'd like to downtrack this but I'm a bit unsure how to debug this. Maybe one thing: How come you set https://my-domain.netlify.app as baseURL, but have https://elastic-poincare-8c5866.netlify.app/contact linked in the last comment? Shouldn't it be the same? Sry I'm not a Netlify user 😋.

AndreyPividori commented 3 years ago

@dword-design Hello ! I was going to reply here, I just found out why it wasn't working. It was a Netlify issue. In my nuxt.config.js file, my target file was target : 'static' because it's run on Netlify. After some research and help (reading Deploy Nuxt on Netlify and Target Property ) I found out that I needed a server target and so it can't be hosted on Netlify because Netlify will use generate command instead of build command. I decided to host it on a server ( I choosed Heroku ) and now it works quite well. So it was NOT a nuxt-mail issue 😁! If any other newbies coming here, hope it can help them.

dword-design commented 3 years ago

So it had server config locally and it worked, but for live Netlify puts it to static? That sounds like weird behavior 😄.

EDIT: Sry haven't seen that you switchted the hoster. Never mind 😋.