I'm using a proxy server on my react front end and a Go server for my back end. When I DON'T use react or a proxy server, the redirect works fine. But when I use react, with its development server and a proxy to my Go back end, the redirect doesn't do anything.
// 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)`
}
You redirect, with
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 => {
<Redirect to="/somewhere/else" />
})