登录
首页 >  Golang >  Go问答

ReactJS 代理服务器不支持服务器重定向

来源:stackoverflow

时间:2024-03-29 14:57:15 234浏览 收藏

IT行业相对于一般传统行业,发展更新速度更快,一旦停止了学习,很快就会被行业所淘汰。所以我们需要踏踏实实的不断学习,精进自己的技术,尤其是初学者。今天golang学习网给大家整理了《ReactJS 代理服务器不支持服务器重定向》,聊聊,我们一起来看看吧!

问题内容

我在 react 前端使用代理服务器,在后端使用 go 服务器。当我不使用反应或代理服务器时,重定向工作正常。但是当我使用 react 及其开发服务器和 go 后端的代理时,重定向不会执行任何操作。

// React package.json file 
"proxy": "http://localhost:5000", // proxy to golang hosted on 5000
    "scripts": {
    "start": "react-scripts start",
},

-----------------------

// golang server

func main() {
    router := gin.Default()
    router.Use(static.Serve("/", static.LocalFile("../client/public", true)))
    ping := router.Group("/path") 
    ping.GET("/ping", pingFunc)
    ping.POST("/ping", pingFuncPost)
    router.Run(":5000")
}

// This redirect is not working.
// In the terminal it shows that a redirect is made but on the frontend
// nothing occurs

func pingFuncPost( c *gin.Context) 
{
    http.Redirect(c.Writer, c.Request, "/page", http.StatusSeeOther)`
}

解决方案


您重定向,使用

const data = {"query": this.state.query};
        fetch(`/path/ping`, {  // should hit the end point of pingFuncPost in golang server, which should redirect to localhost:3000/results
            method: 'POST',
            body: JSON.stringify(data),
        })
.then(res => res.json())
.then(res => {

})

以上就是《ReactJS 代理服务器不支持服务器重定向》的详细内容,更多关于的资料请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>