I have the following handler in my go web application:
func pleaseLoginHandler(w http.ResponseWriter, req *http.Request) {
http.ServeFile(w, req, "./pleaselogin.html")
}
This handler is called for the route http://a.b.org/pleaselogin
by using:
rtr.HandleFunc("/pleaselogin", pleaseLoginHandler)
The application works without any problems locally. Also, it works on the remote server if I run the executable from the folder in which all the application files are present. That is, if the application is in the location /home/username/go/src/appdirectory/appexecfile
and I start the application by going to this directory and starting it as ./appexecfile
then all routes works as expected.
The problem occurs when I start the application using supervisord
. In this case if I visit the route http://a.b.org/pleaselogin
the server returns 404 not found error. My guess is that this is because the http.ServeFile is using a relative path and when the application is started with supervisord
it does not know to look for the file in /home/user/go/src/appdirectory
.
Can someone please suggest a solution to this problem? Can I use another method for serving the file in the golang application that avoids this problem? Or, can I use a setting in supervisord
that makes it look for any file relative to the executable of the application?
Thank you.