From cf5f4b7aaea51f4c4c75d4e47384c989caed0846 Mon Sep 17 00:00:00 2001 From: Xe Date: Sun, 4 Sep 2022 20:35:42 +0000 Subject: snazzy HTML page Signed-off-by: Xe --- cmd/xedn/index.html | 21 +++++++++++++++++++++ cmd/xedn/main.go | 24 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 cmd/xedn/index.html (limited to 'cmd') diff --git a/cmd/xedn/index.html b/cmd/xedn/index.html new file mode 100644 index 0000000..03c4b8e --- /dev/null +++ b/cmd/xedn/index.html @@ -0,0 +1,21 @@ + + + + XeDN + + + + +
+

XeDN

+ +

Hi there! This server is a part of XeDN, the overengineered CDN made by Xe Iaso. I hope you're having a good day. This server can't help you much.

+ + +
+ + diff --git a/cmd/xedn/main.go b/cmd/xedn/main.go index 5c8b540..c6d82b3 100644 --- a/cmd/xedn/main.go +++ b/cmd/xedn/main.go @@ -4,6 +4,7 @@ package main import ( "bytes" "context" + _ "embed" "encoding/gob" "expvar" "flag" @@ -12,6 +13,7 @@ import ( "log" "net/http" "os" + "strconv" "sync" "time" @@ -29,6 +31,9 @@ import ( var ( b2Backend = flag.String("b2-backend", "https://f001.backblazeb2.com", "Backblaze B2 base URL") addr = flag.String("addr", ":8080", "server address") + + //go:embed index.html + indexHTML []byte ) const cacheSize = 128 * 1024 * 1024 // 128 mebibytes @@ -42,6 +47,8 @@ var Group = groupcache.NewGroup("b2-bucket", cacheSize, groupcache.GetterFunc( func(ctx groupcache.Context, key string, dest groupcache.Sink) error { ln.Log(context.Background(), ln.F{"key": key}) + fileHits.Add(key, 1) + resp, err := http.Get(*b2Backend + key) if err != nil { return fmt.Errorf("can't fetch from b2: %v", err) @@ -92,6 +99,9 @@ var ( etagMatches = expvar.NewInt("etag_matches") + fileHits = expvar.NewMap("file_hits") + referers = expvar.NewMap("referers") + etags map[string]string etagLock sync.RWMutex ) @@ -144,6 +154,18 @@ func main() { mux := http.NewServeMux() mux.HandleFunc("/.within/metrics", tsweb.VarzHandler) + + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/" { + http.NotFound(w, r) + return + } + + w.Header().Set("Content-Length", strconv.Itoa(len(indexHTML))) + w.WriteHeader(http.StatusOK) + w.Write(indexHTML) + }) + mux.HandleFunc("/file/christine-static/", func(w http.ResponseWriter, r *http.Request) { etagLock.RLock() etag, ok := etags[r.URL.Path] @@ -155,6 +177,8 @@ func main() { return } + referers.Add(r.Header.Get("Referer"), 1) + var b []byte err := Group.Get(nil, r.URL.Path, groupcache.AllocatingByteSliceSink(&b)) if err != nil { -- cgit v1.2.3