Now I have 3 files and a folder in the same directory like the following. index.html will request the .css, .js(ReactJS) and images inside the folder /img.
After quite a lot of search and try, I know that I can use the following to make a file server to serve the / url request for files inside client/index.
http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir("client/index"))))
It works well. But it only serve static files and I want to make some change to the html file before transferring out such as modifying a value in a tag <input id='projectId' type='hidden' value={{.projectId}}/>. Therefore, I need to register a HandleFunc('/', handler) to execute the html template but the url / is already used for implementing the file server.
What is the proper way to modify the html dynamically while also serving requests to the file system for the files (.css, .js and images inside the folder img)?
server / pghndler / index / index.go
package index
func RegisterHandlers() {
http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir("client/index"))))
http.HandleFunc("/login", loginHandler)
}
