From 8feeceffe497d7e2ae7ae05c9fc57e3be0c3669f Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Sun, 28 Feb 2021 01:44:45 -0600 Subject: [PATCH] sim offline and assert offline support --- main.go | 19 ++++++++++++++----- nullboard.html | 2 ++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 6570672..e3baed7 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,8 @@ import ( ) type server struct { - db storage.DBStream + db storage.DBStream + crud bool } func main() { @@ -20,6 +21,7 @@ func main() { as.Append(args.INT, "p", "port", 8121) as.Append(args.STRING, "db", "db type", "mapstream") as.Append(args.STRING, "dbaddr", "db addr", "/tmp/db") + as.Append(args.BOOL, "nocrud", "no support CRUD api", false) if err := as.Parse(); err != nil { panic(err) } @@ -31,7 +33,8 @@ func main() { dbs := db.(storage.DBStream) server := server{ - db: dbs, + db: dbs, + crud: !as.GetBool("nocrud"), } addr := fmt.Sprintf(":%d", as.GetInt("p")) @@ -50,14 +53,20 @@ func (server server) ServeHTTP(w http.ResponseWriter, r *http.Request) { fileServer := http.FileServer(http.Dir("./")) switch r.URL.Path { case "/api": - logb.Debug("serving api", r.URL.Path, r.URL.Query()) - if err := server.apiHandler(w, r); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + if server.crud { + logb.Debug("serving api", r.URL.Path, r.URL.Query()) + if err := server.apiHandler(w, r); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + return } default: logb.Debug("serving dir", r.URL.Path) fileServer.ServeHTTP(w, r) + return } + logb.Debug("404", r.URL.Path) + http.NotFound(w, r) } func (server server) apiHandler(w http.ResponseWriter, r *http.Request) error { diff --git a/nullboard.html b/nullboard.html index 55008ee..86185ae 100644 --- a/nullboard.html +++ b/nullboard.html @@ -1337,6 +1337,8 @@ syncCacheWithPrimary() { + if (this.pendingSyncCount()) + return; this.syncAWithB(this.cache(), this.primary()); }