I am trying to enter a search query in an input form within my front-end React and retrieve that search query in my Golang server. I am currently running React on the development server on port 3000 and my Goland server on port 5000.
When I enter a query I see the URL change to localhost:3000/?query="Honda" which is what I want, but it does not show up in the backend server and I think it's because I am using 2 different servers. I am aware that I can send the data in a json object but I want to know how to retrieve the values from the URL in the Golang server (serve the React files from the golang server).
// React front end search bar component
<Form action="/path/post" id="searchform" onSubmit={this.handleSubmit}>
<Input value={this.state.query} onChange={this.handleChange} type="text" name="query" />
// React package.json
...
"proxy": "http://localhost:5000",
...
- - - - - - - - - - - - - - - - -
// golang server
...
func main() {
router := gin.Default()
router.Use(static.Serve("/", static.LocalFile("../client/public", true)))
ping := router.Group("/path")
ping.POST("/post", pingFunc)
router.Run(":5000")
}
func post(c *gin.Context) {
c.Request.ParseForm()
q := FormValue("query")
fmt.Println(q)
}
...
Add method="post"
to the form. Eg
<form action="/path/post" method="post" ...