mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 03:18:59 +00:00
Use compiled in assets for those not in STGUIASSETS dir
This commit is contained in:
parent
d3085a4127
commit
3b4fe19dfb
@ -15,6 +15,7 @@ import (
|
||||
"mime"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
@ -128,11 +129,7 @@ func startGUI(cfg config.GUIConfiguration, assetDir string, m *model.Model) erro
|
||||
mux.HandleFunc("/qr/", getQR)
|
||||
|
||||
// Serve compiled in assets unless an asset directory was set (for development)
|
||||
if len(assetDir) > 0 {
|
||||
mux.Handle("/", http.FileServer(http.Dir(assetDir)))
|
||||
} else {
|
||||
mux.HandleFunc("/", embeddedStatic)
|
||||
}
|
||||
mux.Handle("/", embeddedStatic(assetDir))
|
||||
|
||||
// Wrap everything in CSRF protection. The /rest prefix should be
|
||||
// protected, other requests will grant cookies.
|
||||
@ -536,7 +533,8 @@ func validAPIKey(k string) bool {
|
||||
return len(apiKey) > 0 && k == apiKey
|
||||
}
|
||||
|
||||
func embeddedStatic(w http.ResponseWriter, r *http.Request) {
|
||||
func embeddedStatic(assetDir string) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
file := r.URL.Path
|
||||
|
||||
if file[0] == '/' {
|
||||
@ -547,8 +545,18 @@ func embeddedStatic(w http.ResponseWriter, r *http.Request) {
|
||||
file = "index.html"
|
||||
}
|
||||
|
||||
if assetDir != "" {
|
||||
p := filepath.Join(assetDir, filepath.FromSlash(file))
|
||||
_, err := os.Stat(p)
|
||||
if err == nil {
|
||||
http.ServeFile(w, r, p)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
bs, ok := auto.Assets[file]
|
||||
if !ok {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
@ -560,4 +568,5 @@ func embeddedStatic(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Last-Modified", modt)
|
||||
|
||||
w.Write(bs)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user