У меня есть следующий код:
const { v4: uuidv4 } = require('uuid')
const functions = require('firebase-functions')
const nodemailer = require('nodemailer')
const cors = require('cors')({ origin: true })
const gmailEmail = functions.config().gmail.email
const gmailPassword = functions.config().gmail.password
const mailto = functions.config().gmail.mailto
const mailTransport = nodemailer.createTransport({
service: 'gmail',
auth: {
user: gmailEmail,
pass: gmailPassword
}
})
exports.sendMail = functions.https.onRequest((req, res) => {
cors(req, res, () => {
const items = req.body.items.forEach(item => (
`${item.quantity} x ${item.uuid} (${item.name})\n`
))
if (req.method === 'POST') {
const mailOptions = {
from: gmailEmail,
replyTo: gmailEmail,
to: mailto,
subject: `Order ${uuidv4()} from ${req.body.name} (${req.body.email})`,
text: `Order\n\n${items}`
}
mailTransport.sendMail(mailOptions)
res.status(200).send(JSON.stringify({ status: 'OK' }))
} else {
res.status(400).send(JSON.stringify({ status: 'method not allowed' }))
}
})
})
По какой-то причине это сработало один раз, а затем продолжает давать мне
Access to fetch at 'https://xxxxx.cloudfunctions.net/sendMail' from origin 'https://xxxx.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Чего мне не хватает? Если возможно, я бы хотел избежать использования Express.