Use relative path for static directory
This commit is contained in:
parent
9fc22e4972
commit
9b27a67a21
1 changed files with 6 additions and 3 deletions
9
main.go
9
main.go
|
|
@ -5,6 +5,7 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var PublishedImgDir string
|
||||
|
|
@ -43,10 +44,12 @@ func main() {
|
|||
log.Println("Registering handlers...")
|
||||
authFunc := func (r *http.Request) (*User){ return Authenticate(*htpasswd, r) }
|
||||
|
||||
staticDir, _ := filepath.Abs(filepath.Join(filepath.Dir(os.Args[0]), "static"))
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/index.html") })
|
||||
mux.Handle("/css/", http.FileServer(http.Dir("./static")))
|
||||
mux.Handle("/js/", http.FileServer(http.Dir("./static")))
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, filepath.Join(staticDir, "index.html")) })
|
||||
mux.Handle("/css/", http.FileServer(http.Dir(staticDir)))
|
||||
mux.Handle("/js/", http.FileServer(http.Dir(staticDir)))
|
||||
|
||||
mux.Handle("/api/", http.StripPrefix("/api", ApiHandler(authFunc)))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue