如何使我的react应用程序获取我的代理API



我的api调用没有发送到代理url域。我知道它没有呼叫,因为服务器上的控制台日志没有关闭。有人能帮我吗?

//client package.json
"proxy":"http://localhost:3001"
//client app
useEffect(() => {
const apicall = async () => {
try{
const response = await fetch("/")
if (response.status !== 200){
throw new Error()
}
else{
console.log("api call was success")
console.log(response)
}
} catch(error){
console.log(error)
}}
apicall()
}, [])
//server
app.get("*", (req,res)=>{
console.log("apicalled")
res.cookie("refreshToken", 987654321, {
maxAge: 60000,
httpOnly: true
})
res.send("has cookie sent?")
})

没有答案,但看起来你正在使用create-react应用程序?我认为,如果您已经设置了自己的服务器,就不需要在package.json中设置代理。

我正在运行一个小型react应用程序,并试图访问我公司代理背后的外部api。我仍然会遇到cors错误——我曾尝试在package.json中设置代理并使用setupProxy.js(单独使用(,但运气不佳。

最新更新