从Google Cloud函数到我的Web应用程序的错误500

时间:2019-09-19 18:21:43

标签: javascript node.js google-cloud-functions

我已经设置了谷歌云功能(在测试中效果很好),它无法将响应发送回前端: 错误:

    Uncaught (in promise) Error: Network Error
    at createError (createError.js?2d83:16)
    at XMLHttpRequest.handleError (xhr.js?b50d:81)

云功能:

exports.helloWorld = (req, res) => {
      (async () => {
    let se = []
    for (let i =0;i<req.body.url.length;i++){
      let se1 = req.body.searchPhrase + " site:" + req.body.url[i]
      se.push(se1.toString())
    }
         console.log(se)
    let scrape_job = {
        search_engine: 'bing',
        keywords: se,
        num_pages: '1',
    };
console.log(req.body.searchPhrase)
 results =  await se_scraper.scrape({}, scrape_job);
    res.set('Access-Control-Allow-Origin', '*');
    res.set('Access-Control-Allow-Methods', 'POST');
    res.set('Access-Control-Allow-Headers', 'Content-Type:application/json');
    res.set('Access-Control-Max-Age', '3600');
    res.json({
      status: true,
      message: "Challenges found !",
      results: "yes"
    });
  })();

};

我使用axios.post发送请求 前端功能:

 axios
 .post("https://us-central1-astute-loop-252111.cloudfunctions.net/scrap",newData)
 .then((res)=>{
   console.log(res)
   d = d.contact(res.data.results.results)
  })

我很高兴获得帮助

0 个答案:

没有答案