在构建web应用程序时,我如何绕过客户端的cors错误?



我正试图在我的下一个应用程序中使用axios向githubjobs API发出get请求。我已经正确地设置和配置了axios。下面是我想要分派的动作:

async defaultJobsFetch({commit}){
try{
const res = await axios.get('https://jobs.github.com/positions.json?location=new+york')
const jobs = res.data;
commit('getJobs', jobs)
}catch(error){
commit("errored");
console.log(error)
}
finally{
commit('changeLoading')
}
},

我也试过使用https://cors-anywhere.herokupp.com/,但我仍然得到一个错误403禁止

我注意到它在我的本地机器上工作得很好,但是当我部署,并尝试加载部署的应用程序时,我没有得到响应,而是得到403错误。该应用程序托管在heroku上,http://hubjobs.herokuapp.com,当您访问该站点时检查控制台,看到错误

一个解决方法是使用chrome扩展,如CORS unblock或尝试在header:

Access-Control-Allow-Origin: *

你可以试试cors.bridged.cc而不是cors-anywhere.herokupp.com

最新更新