Make it so the playground can decide which index file to serve. (#223)
* Make it so the playground can decide which index file to serve. Also remove special index-nw.html and use the current playground config to decide if to show the windows instances option or not. * Give a better name to the struct
This commit is contained in:
committed by
Marcos Nils
parent
2e039a4e60
commit
f277e3776c
@@ -77,6 +77,7 @@ func Register(extend HandlerExtender) {
|
||||
r.HandleFunc("/oauth/providers/{provider}/callback", LoginCallback).Methods("GET")
|
||||
r.HandleFunc("/playgrounds", NewPlayground).Methods("PUT")
|
||||
r.HandleFunc("/playgrounds", ListPlaygrounds).Methods("GET")
|
||||
r.HandleFunc("/my/playground", GetCurrentPlayground).Methods("GET")
|
||||
|
||||
corsRouter.HandleFunc("/", NewSession).Methods("POST")
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
@@ -28,8 +29,8 @@ func Home(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !playground.AllowWindowsInstances {
|
||||
http.ServeFile(w, r, "./www/index-nw.html")
|
||||
if playground.IndexFile != "" {
|
||||
http.ServeFile(w, r, fmt.Sprintf("./www/%s", playground.IndexFile))
|
||||
} else {
|
||||
http.ServeFile(w, r, "./www/index.html")
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/play-with-docker/play-with-docker/config"
|
||||
"github.com/play-with-docker/play-with-docker/pwd/types"
|
||||
@@ -51,6 +52,32 @@ func ListPlaygrounds(rw http.ResponseWriter, req *http.Request) {
|
||||
json.NewEncoder(rw).Encode(playgrounds)
|
||||
}
|
||||
|
||||
type PlaygroundConfigurationResponse struct {
|
||||
Id string `json:"id"`
|
||||
Domain string `json:"domain"`
|
||||
DefaultDinDInstanceImage string `json:"default_dind_instance_image"`
|
||||
AvailableDinDInstanceImages []string `json:"available_dind_instance_images"`
|
||||
AllowWindowsInstances bool `json:"allow_windows_instances"`
|
||||
DefaultSessionDuration time.Duration `json:"default_session_duration"`
|
||||
}
|
||||
|
||||
func GetCurrentPlayground(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.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
json.NewEncoder(rw).Encode(PlaygroundConfigurationResponse{
|
||||
Id: playground.Id,
|
||||
Domain: playground.Domain,
|
||||
DefaultDinDInstanceImage: playground.DefaultDinDInstanceImage,
|
||||
AvailableDinDInstanceImages: playground.AvailableDinDInstanceImages,
|
||||
AllowWindowsInstances: playground.AllowWindowsInstances,
|
||||
DefaultSessionDuration: playground.DefaultSessionDuration,
|
||||
})
|
||||
}
|
||||
|
||||
func validateToken(req *http.Request) bool {
|
||||
_, password, ok := req.BasicAuth()
|
||||
if !ok {
|
||||
Reference in New Issue
Block a user