-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[question] Gorilla/Mux SPA not working #2
Comments
MIGRATED Confirming I have the same problem with the example SPA code (using Windows). // get the absolute path to prevent directory traversal
path, err := filepath.Abs(r.URL.Path)
if err != nil {
// if we failed to get the absolute path respond with a 400 bad request
// and stop
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
fmt.Println(path) // returns: D:\
// prepend the path with the path to the static directory
path = filepath.Join(h.StaticPath, path)
fmt.Println(path) // returns: build\D:
path = filepath.Join(h.StaticPath, r.URL.Path)
fmt.Println(path) // returns: build |
MIGRATED This problem appears on windows. path, err := filepath.Abs(r.URL.Path)
path = strings.Replace(path, `C:\`, "/", 1) Solution found on reddit : I'm beginner in golang (even more with windows stuff) so i don't feel comfortable to make a pull request but at least here is quick and dirty hotfix ! |
Fix/update readme serve spa fixes #2
Merging to temp branch to review |
MIGRATED
From mux created by AstroNik: gorilla#588
Problem
So I'm not really sure if this is a bug or anything, and this is also my first bug report so I apologize for my lack of knowledge on correctly reporting a bug.
I was trying to create a SPA using gorilla/mux and kept running into issues with displaying my webpage. I knew my code was correct but it had something to do with the file paths inside the SPA handler itself because when I was running my code I was getting a StatusInternalServerError. All my file paths were correct so it had to be something with the ServeHTTP function itself. I later found it to be an issue with the path as shown below.
Versions
go version go1.13.4 windows/amd64
github.com/gorilla/mux v1.7.4
…
main.go
Code was changed to below, and started to work perfectly fine.
…
I don't know whether or not to report this as a fix to the actual public code or not. Still new to contributing.
The text was updated successfully, but these errors were encountered: