Add error to GetSession return values
- Add button to copy instance SSH access
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/play-with-docker/play-with-docker/config"
|
||||
"github.com/play-with-docker/play-with-docker/event"
|
||||
"github.com/play-with-docker/play-with-docker/pwd"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/urfave/negroni"
|
||||
)
|
||||
@@ -27,8 +28,19 @@ var core pwd.PWDApi
|
||||
var e event.EventApi
|
||||
var landings = map[string][]byte{}
|
||||
|
||||
var latencyHistogramVec = prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Name: "pwd_handlers_duration_ms",
|
||||
Help: "How long it took to process a specific handler, in a specific host",
|
||||
Buckets: []float64{300, 1200, 5000},
|
||||
}, []string{"action"})
|
||||
|
||||
type HandlerExtender func(h *mux.Router)
|
||||
|
||||
func init() {
|
||||
prometheus.MustRegister(latencyHistogramVec)
|
||||
|
||||
}
|
||||
|
||||
func Bootstrap(c pwd.PWDApi, ev event.EventApi) {
|
||||
core = c
|
||||
e = ev
|
||||
@@ -53,6 +65,10 @@ func Register(extend HandlerExtender) {
|
||||
corsRouter.HandleFunc("/sessions/{sessionId}/instances/{instanceName}", DeleteInstance).Methods("DELETE")
|
||||
corsRouter.HandleFunc("/sessions/{sessionId}/instances/{instanceName}/exec", Exec).Methods("POST")
|
||||
|
||||
r.HandleFunc("/sessions/{sessionId}/instances/{instanceName}/editor.html", func(rw http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(rw, r, "www/editor.html")
|
||||
})
|
||||
|
||||
r.HandleFunc("/ooc", func(rw http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(rw, r, "./www/ooc.html")
|
||||
}).Methods("GET")
|
||||
@@ -64,9 +80,6 @@ func Register(extend HandlerExtender) {
|
||||
r.HandleFunc("/robots.txt", func(rw http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(rw, r, "www/robots.txt")
|
||||
})
|
||||
r.HandleFunc("/sdk.js", func(rw http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(rw, r, "www/sdk.js")
|
||||
})
|
||||
|
||||
corsRouter.HandleFunc("/sessions/{sessionId}/ws/", WSH)
|
||||
r.Handle("/metrics", promhttp.Handler())
|
||||
@@ -90,6 +103,7 @@ func Register(extend HandlerExtender) {
|
||||
}
|
||||
|
||||
n := negroni.Classic()
|
||||
|
||||
r.PathPrefix("/").Handler(negroni.New(negroni.Wrap(corsHandler(corsRouter))))
|
||||
n.UseHandler(r)
|
||||
|
||||
@@ -128,7 +142,11 @@ func Register(extend HandlerExtender) {
|
||||
rr.HandleFunc("/ping", Ping).Methods("GET")
|
||||
rr.Handle("/metrics", promhttp.Handler())
|
||||
rr.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(rw, r, fmt.Sprintf("https://%s", r.Host), http.StatusMovedPermanently)
|
||||
target := fmt.Sprintf("https://%s%s", r.Host, r.URL.Path)
|
||||
if len(r.URL.RawQuery) > 0 {
|
||||
target += "?" + r.URL.RawQuery
|
||||
}
|
||||
http.Redirect(rw, r, target, http.StatusMovedPermanently)
|
||||
})
|
||||
nr := negroni.Classic()
|
||||
nr.UseHandler(rr)
|
||||
|
||||
Reference in New Issue
Block a user