์ด๊ฒ์ ๋๋ค์ฉ netlify ํจ์ ํธ๋ค๋ฌ์ ๋ฃ์ต๋๋ค.
// For more info, check https://www.netlify.com/docs/functions/#javascript-lambda-functions
export function handler(event, context, callback) {
console.log('sending')
console.log(event)
console.log(context)
const sgMail = require('@sendgrid/mail')
sgMail.setApiKey(process.env.SENDGRID_API_KEY)
const msg = {
to: '[email protected]',
from: '[email protected]',
templateId: '#ID',
dynamic_template_data: {
recipient: 'alex',
},
}
sgMail.send(msg).catch(function(error) {
console.log(error)
})
console.log('sent sign up')
}
๋๋ ๋ค์์ ์ป๋๋ค
TypeError: s is not a function
at e.exports.deepMergeDynamicTemplateData (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:127:27164)
at p.applyDynamicTemplateData (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:211:117545)
at p.addPersonalization (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:211:116796)
at p.addTo (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:211:116994)
at p.fromData (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:211:115579)
at new p (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:211:114482)
at Function.create (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:211:120622)
at e.exports.send (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:1:156753)
at Object.a.handler (/Users/amlcodes/Documents/projects/cctmvp/lambda/mailinglist.js:127:36900)
at /Users/amlcodes/Documents/projects/cctmvp/node_modules/netlify-lambda/lib/serve.js:79:27
at Layer.handle [as handle_request] (/Users/amlcodes/Documents/projects/cctmvp/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/amlcodes/Documents/projects/cctmvp/node_modules/express/lib/router/route.js:137:13)
at next (/Users/amlcodes/Documents/projects/cctmvp/node_modules/express/lib/router/route.js:131:14)
at next (/Users/amlcodes/Documents/projects/cctmvp/node_modules/express/lib/router/route.js:131:14)
at next (/Users/amlcodes/Documents/projects/cctmvp/node_modules/express/lib/router/route.js:131:14)
at next (/Users/amlcodes/Documents/projects/cctmvp/node_modules/express/lib/router/route.js:131:14)
[HPM] Error occurred while trying to proxy request mailinglist from localhost:8000 to http://localhost:9000 (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)
์ด ์ ํ๋ก
fetch('/.netlify/functions/mailinglist', {
method: 'POST',
body: JSON.stringify({
// recipient: this.state.recipient,
recipient: 'alex',
}),
headers: new Headers({
'Content-Type': 'application/json',
}),
})
.then(res => {
console.log('Signup processed successfully')
this.setState({ signupmessage: 'Signup Successful!' })
return res
})
.catch(error => {
console.error('Error:', error)
this.setState({ signupmessage: 'Signup Failed' })
})
์์ฑ๋ mailinglist.js์ this.dynamicTemplateData=s(e,this.dynamicTemplateData)}}
์๋ ํ์ธ์ @amlcodes ์ ๋๋ค .
Netlify๊ฐ s
ํจ์๊ฐ ๋ฌด์์ธ์ง ์ ์ํ์ง ์๊ณ ์ด ์ฝ๋ s(e,this.dynamicTemplateData)
๋ฅผ ์ถ๊ฐํ ๊ฒ ๊ฐ์ต๋๋ค. ๊ทธ ์ค์ ์ ๊ฑฐํ๋ฉด ์ด๋ป๊ฒ ๋ฉ๋๊น?
๋ง์์ ๋ด์,
์๋จธ
๋๋์ด ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
templateId
์ฌ์ฉํ ๋๋ง ๋ฐ์ํฉ๋๋ค. Netlify์์๋ง ๋ฐ์ํฉ๋๋ค(๋ก์ปฌ ๋จธ์ ์ธ ๋
ธ๋ 10.16.0์์๋ ๋ฌธ์ ์์ด ์๋ํจ).
ํด๋น ์ค์ ์ ๊ฑฐํ๊ณ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ ๋ฐฉ๋ฒ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ๋ฌธ์ ๋ Netlify์๋ง ์์ต๋๋ค.
์ถ์๋ฅผ ํด์ ํ์ฌ ๊ทผ๋ณธ์ ์ธ ๋ฌธ์ ๊ฐ ๋ฌด์์ธ์ง ํ์ธํ ์ ์์ต๋๊น? https://github.com/netlify/netlify-lambda#debugging
์ค์ ๋ก ์ด๊ฒ์ https://github.com/sendgrid/sendgrid-nodejs/pull/1039์ ์ํด ์์ ๋ ๊ฒ์ด๋ผ๊ณ ํ์ ํฉ๋๋ค.