sendinblue API を使用して、オファー ページに表示される連絡先 (電子メール) を作成していますが、成功アラートを受け取った後、何も起こらず、多くのことを試しましたが、エラーが発生し続けます。
オファー ページがレンダリングされず、res.redirect("offer") を試してみましたが、まだ何も起こりません。メール パラメーターをオファー ページに渡す必要があるため、このメソッドも使用できません。
これは私のindex.jsです
const bodyparser = require('body-parser')
const SibApiV3Sdk = require('sib-api-v3-sdk');
const path = require('path')
const app = express()
const env = require('dotenv').config({path: './.env'});
const port = process.env.PORT || 3000
app.use(bodyparser.urlencoded({extended:false}))
app.use(bodyparser.json())
// View Engine Setup
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'ejs')
app.get('/',(req,res)=>{
res.sendFile(__dirname + "/email.html");
})
app.listen(port, function(error){
if(error) throw error
console.log("Server created Successfully")
})
// send email endpoint
app.post("/sendemail", (req, res, next) => {
const email = req.query.email;
console.log(email);
let apikey = process.env.SIB_API_KEY
// auth + setup
let defaultClient = SibApiV3Sdk.ApiClient.instance;
let apiKey = defaultClient.authentications['api-key'];
apiKey.apiKey = apikey;
// create contact
let apiInstance = new SibApiV3Sdk.ContactsApi();
let createContact = new SibApiV3Sdk.CreateContact();
createContact.email = email;
createContact.listIds = [2];
apiInstance.createContact(createContact).then((data) => {
// success
res.render('offer',{email:email,
publishablekey: Publishable_Key
})
}, function (error) {
// error
console.log(error)
res.status(500);
res.send("failure");
})
})
app.get('/offer', (req, res) => {
res.render('offer')
});
これは私のemail.htmlページにあります
<script>
document.getElementById("submit").onclick = () => {
// console.log(email.value)
fetch("/sendemail?email=" + email.value, {
method: "POST"
}).then((res) => {
// success
alert("success")
}).catch((err) => {
// error
alert(err)
})}
</script>