0

我正在尝试将带有节点服务器的 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 })
    })
}

4

0 回答 0