@NDll

Отправка писем из nuxtjs с помощью sendpulse?

есть метод отправки формы

sendToEmail() {
                let email = {
                    html: "<p>Your email content goes here</p>",
                    text: this.text,
                    subject: "Testing SendPulse API",
                    from: {
                        name: "Your Sender Name",
                        email: "artem@aprint.pro"
                    },
                    to: [
                        {
                            name: this.name,
                            email: this.email
                        }
                    ]
                };
                console.log(email);
                let answerGetter = function answerGetter(data) {
                    console.log(data);
                };
                this.$axios.$post("/api/email", email);
            }


файл nuxt.config

serverMiddleware: [
{ path: '/api', handler: '~/api/email.js' }
],

создал папку api и в ней файл email.js

export default function (req, res, next) {

    let sendpulse = require("sendpulse-api");
    /*
     * https://login.sendpulse.com/settings/#api
     */
    let API_USER_ID = "123";
    let API_SECRET = "2313";

    sendpulse.init(API_USER_ID,API_SECRET,TOKEN_STORAGE,function() {
        sendpulse.listAddressBooks(console.log);
    });

        // req is the Node.js http request object
    console.log('sdfsd')

    // res is the Node.js http response object

    // next is a function to call to invoke the next middleware
    // Don't forget to call next at the end if your middleware is not an endpoint!
    next()
}


но при клике отправить сообщение выдает

xhr.js?b50d:178 POST http://localhost:3000/api/email 404 (Not Found)
dispatchXhrRequest @ xhr.js?b50d:178
xhrAdapter @ xhr.js?b50d:12
dispatchRequest @ dispatchRequest.js?5270:52
Promise.then (async)
request @ Axios.js?0a06:61
Axios.<computed> @ Axios.js?0a06:86
wrap @ bind.js?1d2b:9
axiosExtra.<computed> @ axios.js?10e8:45
sendToEmail @ Footer.vue?cd7b:135
submit @ Footer.vue?d21c:25
invokeWithErrorHandling @ vue.runtime.esm.js?2b0e:1854
invoker @ vue.runtime.esm.js?2b0e:2179
original._wrapper @ vue.runtime.esm.js?2b0e:6917
createError.js?2d83:16 Uncaught (in promise) Error: Request failed with status code 404
    at createError (createError.js?2d83:16)
    at settle (settle.js?467f:17)
    at XMLHttpRequest.handleLoad (xhr.js?b50d:61)
  • Вопрос задан
  • 251 просмотр
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы