Files
play-with-docker/handlers/home.go
Jonathan Leibiusky f277e3776c 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
2017-11-22 16:47:01 -03:00

38 lines
818 B
Go

package handlers
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
)
func Home(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
sessionId := vars["sessionId"]
s := core.SessionGet(sessionId)
if s == nil {
// Session doesn't exist (can happen if closing the sessions an reloading the page, or similar).
w.WriteHeader(http.StatusNotFound)
return
}
if s.Stack != "" {
go core.SessionDeployStack(s)
}
playground := core.PlaygroundGet(s.PlaygroundId)
if playground == nil {
log.Printf("Playground with id %s for session %s was not found!", s.PlaygroundId, s.Id)
w.WriteHeader(http.StatusBadRequest)
return
}
if playground.IndexFile != "" {
http.ServeFile(w, r, fmt.Sprintf("./www/%s", playground.IndexFile))
} else {
http.ServeFile(w, r, "./www/index.html")
}
}