我正在尝试将一个带有节点服务器的nextJS部署到Zeit Now。
这是我的脚本,我尝试部署下面的代码,但是由于axios请求,只要我点击“ / api / subscribe”路由,应用程序就会崩溃。得到的错误是502 NO_STATUS_CODE_FROM_FUNCTION
import axios from 'axios'
import { NowRequest, NowResponse } from '@now/node'
export default function(req: NowRequest, res: NowResponse) {
const { email } = req.body
const MAILCHIMP_API_KEY = process.env.MAILCHIMP_API_KEY
const MAILCHIMP_LIST_ID = process.env.MAILCHIMP_LIST_ID
const MAILCHIMP_INSTANCE = process.env.MAILCHIMP_INSTANCE
const subscriber = {
email_address: email,
status: 'subscribed'
}
axios({
method: 'POST',
url: `https://${MAILCHIMP_INSTANCE}.api.mailchimp.com/3.0/lists/${MAILCHIMP_LIST_ID}/members/`,
data: subscriber,
headers: {
Authorization: `apikey ${MAILCHIMP_API_KEY}`,
'Content-Type': 'application/json'
}
})
.then(({ data }) => {
const { status } = data
res.status(200).send({ success: status })
})
.catch(({ response }) => {
const { data } = response
const { status, detail } = data
res.status(status).send({ error: detail })
})
}