From e53123d8fa6f046278085cea81703cc0394f0dc9 Mon Sep 17 00:00:00 2001 From: Daniel Heath Date: Sat, 28 Apr 2018 19:54:44 +1000 Subject: [PATCH] Add herdyo command for an example of a multisite --- cmd/herdyo/herdyo.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 cmd/herdyo/herdyo.go diff --git a/cmd/herdyo/herdyo.go b/cmd/herdyo/herdyo.go new file mode 100644 index 0000000..0f175a9 --- /dev/null +++ b/cmd/herdyo/herdyo.go @@ -0,0 +1,42 @@ +package main + +import ( + "net/http" + "strings" + + "github.com/gin-contrib/sessions" + "github.com/schollz/cowyo/server" +) + +func main() { + store := sessions.NewCookieStore([]byte("secret")) + + first := server.Site{ + PathToData: "site1", + Debounce: 500, + SessionStore: store, + AllowInsecure: true, + HotTemplateReloading: true, + Fileuploads: true, + MaxUploadSize: 2, + }.Router() + + second := server.Site{ + PathToData: "site2", + Debounce: 500, + SessionStore: store, + AllowInsecure: true, + HotTemplateReloading: true, + Fileuploads: true, + MaxUploadSize: 2, + }.Router() + panic(http.ListenAndServe("localhost:8000", http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { + if strings.HasPrefix(r.Host, "first") { + first.ServeHTTP(rw, r) + } else if strings.HasPrefix(r.Host, "second") { + second.ServeHTTP(rw, r) + } else { + http.NotFound(rw, r) + } + }))) +}