Enable use of override for session timeout in hours, fix captcha bypass bug. (#51)
* - Enable use of override for session timeout. This is more useful than having to hard-code and rebuild the code for the previous 4 hour limit. Just set environmental variable and start the app. - Future work may involve breaking down into minutes, but this is a good minimum delivery to provide value to end-user/developer. - Fixes bug in Captcha code by introducing new landing page. This is not a new go template, it's a separate HTML file because SRP - single reponsibility principle. Happy for this to be refacted after merging commit. - Fix for including Docker 1.12 override has been removed for later PR. * Merge * Reinstate 'material' JS include' * https for JS includes * HTTPs for JS in bypass
This commit is contained in:
27
api.go
27
api.go
@@ -5,28 +5,24 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"flag"
|
||||
"strconv"
|
||||
|
||||
"github.com/franela/play-with-docker/handlers"
|
||||
"github.com/franela/play-with-docker/services"
|
||||
"github.com/franela/play-with-docker/templates"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/urfave/negroni"
|
||||
"flag"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
var portNumber int
|
||||
flag.IntVar(&portNumber, "port", 3000, "Give a TCP port to run the application")
|
||||
flag.Parse()
|
||||
|
||||
welcome, tmplErr := templates.GetWelcomeTemplate()
|
||||
if tmplErr != nil {
|
||||
log.Fatal(tmplErr)
|
||||
}
|
||||
bypassCaptcha := len(os.Getenv("GOOGLE_RECAPTCHA_DISABLED")) > 0
|
||||
|
||||
server := services.CreateWSServer()
|
||||
|
||||
server.On("connection", handlers.WS)
|
||||
server.On("error", handlers.WSError)
|
||||
|
||||
@@ -45,9 +41,19 @@ func main() {
|
||||
r.StrictSlash(false)
|
||||
|
||||
r.HandleFunc("/ping", http.HandlerFunc(handlers.Ping)).Methods("GET")
|
||||
|
||||
r.HandleFunc("/", http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
rw.Write(welcome)
|
||||
if bypassCaptcha {
|
||||
http.ServeFile(rw, r, "./www/bypass.html")
|
||||
} else {
|
||||
welcome, tmplErr := templates.GetWelcomeTemplate()
|
||||
if tmplErr != nil {
|
||||
log.Fatal(tmplErr)
|
||||
}
|
||||
rw.Write(welcome)
|
||||
}
|
||||
})).Methods("GET")
|
||||
|
||||
r.HandleFunc("/", http.HandlerFunc(handlers.NewSession)).Methods("POST")
|
||||
|
||||
r.HandleFunc("/sessions/{sessionId}", http.HandlerFunc(handlers.GetSession)).Methods("GET")
|
||||
@@ -57,6 +63,7 @@ func main() {
|
||||
h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "./www/index.html")
|
||||
})
|
||||
|
||||
r.HandleFunc("/p/{sessionId}", h).Methods("GET")
|
||||
r.PathPrefix("/assets").Handler(http.FileServer(http.Dir("./www")))
|
||||
r.HandleFunc("/robots.txt", http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
@@ -68,7 +75,7 @@ func main() {
|
||||
n := negroni.Classic()
|
||||
n.UseHandler(r)
|
||||
|
||||
log.Println("Listening on port "+ strconv.Itoa(portNumber))
|
||||
log.Println("Listening on port " + strconv.Itoa(portNumber))
|
||||
log.Fatal(http.ListenAndServe("0.0.0.0:"+strconv.Itoa(portNumber), n))
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user