Now both index.html and landing.html can be changes for specific (#224)
playgrounds. By default they will be served from `www/default` if no override has been specified
This commit is contained in:
committed by
Marcos Nils
parent
f277e3776c
commit
65b8364ef2
@@ -66,9 +66,7 @@ func Register(extend HandlerExtender) {
|
|||||||
r.Handle("/metrics", promhttp.Handler())
|
r.Handle("/metrics", promhttp.Handler())
|
||||||
|
|
||||||
// Generic routes
|
// Generic routes
|
||||||
r.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
|
r.HandleFunc("/", Landing).Methods("GET")
|
||||||
http.ServeFile(rw, r, "./www/landing.html")
|
|
||||||
}).Methods("GET")
|
|
||||||
|
|
||||||
corsRouter.HandleFunc("/users/me", LoggedInUser).Methods("GET")
|
corsRouter.HandleFunc("/users/me", LoggedInUser).Methods("GET")
|
||||||
r.HandleFunc("/users/{userId:^(?me)}", GetUser).Methods("GET")
|
r.HandleFunc("/users/{userId:^(?me)}", GetUser).Methods("GET")
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
@@ -29,9 +30,26 @@ func Home(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if playground.IndexFile != "" {
|
index := filepath.Join("./www", playground.AssetsDir, "/index.html")
|
||||||
http.ServeFile(w, r, fmt.Sprintf("./www/%s", playground.IndexFile))
|
if _, err := os.Stat(index); os.IsNotExist(err) {
|
||||||
} else {
|
index = "./www/default/index.html"
|
||||||
http.ServeFile(w, r, "./www/index.html")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
http.ServeFile(w, r, index)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Landing(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
playground := core.PlaygroundFindByDomain(req.Host)
|
||||||
|
if playground == nil {
|
||||||
|
log.Printf("Playground for domain %s was not found!", req.Host)
|
||||||
|
rw.WriteHeader(http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
index := filepath.Join("./www", playground.AssetsDir, "/landing.html")
|
||||||
|
if _, err := os.Stat(index); os.IsNotExist(err) {
|
||||||
|
index = "./www/default/landing.html"
|
||||||
|
}
|
||||||
|
|
||||||
|
http.ServeFile(rw, req, index)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,6 @@ type Playground struct {
|
|||||||
AllowWindowsInstances bool `json:"allow_windows_instances" bson:"allow_windows_instances"`
|
AllowWindowsInstances bool `json:"allow_windows_instances" bson:"allow_windows_instances"`
|
||||||
DefaultSessionDuration time.Duration `json:"default_session_duration" bson:"default_session_duration"`
|
DefaultSessionDuration time.Duration `json:"default_session_duration" bson:"default_session_duration"`
|
||||||
Extras PlaygroundExtras `json:"extras" bson:"extras"`
|
Extras PlaygroundExtras `json:"extras" bson:"extras"`
|
||||||
IndexFile string `json:"index_file" bson:"index_file"`
|
AssetsDir string `json:"assets_dir" bson:"assets_dir"`
|
||||||
Tasks []string `json:"tasks" bson:"tasks"`
|
Tasks []string `json:"tasks" bson:"tasks"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user