cebulacamp/landing: build and push backend
Change-Id: I1336fb2fe52de7c42e5de0c4f1e05f42c32a9777
diff --git a/hswaw/cebulacamp/landing/backend/main.go b/hswaw/cebulacamp/landing/backend/main.go
new file mode 100644
index 0000000..1416d07
--- /dev/null
+++ b/hswaw/cebulacamp/landing/backend/main.go
@@ -0,0 +1,49 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "mime"
+ "net/http"
+ "strings"
+
+ "github.com/golang/glog"
+
+ "code.hackerspace.pl/hscloud/hswaw/cebulacamp/landing/static"
+)
+
+var (
+ flagBind string
+)
+
+func init() {
+ flag.Set("logtostderr", "true")
+}
+
+func main() {
+ flag.StringVar(&flagBind, "bind", "0.0.0.0:8080", "Address at which to serve HTTP requests")
+ flag.Parse()
+ http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ path := r.URL.Path
+ if path == "/" {
+ path = "/index.html"
+ }
+ path = strings.TrimPrefix(path, "/")
+ staticPath := fmt.Sprintf("hswaw/cebulacamp/landing/%s", path)
+ if data, ok := static.Data[staticPath]; ok {
+ parts := strings.Split(path, ".")
+ ext := fmt.Sprintf(".%s", parts[len(parts)-1])
+ t := mime.TypeByExtension(ext)
+ w.Header().Set("Content-Type", t)
+ w.Write(data)
+ } else {
+ http.NotFound(w, r)
+ }
+ })
+
+ glog.Infof("Starting up at %v", flagBind)
+ err := http.ListenAndServe(flagBind, nil)
+ if err != nil {
+ glog.Exit(err)
+ }
+}