diff options
| author | Xe <me@christine.website> | 2022-09-04 20:35:42 +0000 |
|---|---|---|
| committer | Xe <me@christine.website> | 2022-09-04 20:35:42 +0000 |
| commit | cf5f4b7aaea51f4c4c75d4e47384c989caed0846 (patch) | |
| tree | c18c375fbbb5191085adde499be2ece57cb5284e /cmd/xedn | |
| parent | 143e320398c509c868fc31cae5dfe628fb5b29d2 (diff) | |
| download | x-cf5f4b7aaea51f4c4c75d4e47384c989caed0846.tar.xz x-cf5f4b7aaea51f4c4c75d4e47384c989caed0846.zip | |
snazzy HTML page
Signed-off-by: Xe <me@christine.website>
Diffstat (limited to 'cmd/xedn')
| -rw-r--r-- | cmd/xedn/index.html | 21 | ||||
| -rw-r--r-- | cmd/xedn/main.go | 24 |
2 files changed, 45 insertions, 0 deletions
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 @@ +<!DOCTYPE html> +<html> + <head> + <title>XeDN</title> + <style> + main{font-family:monospace,monospace;max-width:38rem;padding:2rem;margin:auto}@media only screen and (max-device-width:736px){main{padding:0}}::selection{background:#d3869b}body{background:#282828;color:#ebdbb2}pre{background-color:#3c3836;padding:1em;border:0}a,a:active,a:visited{color:#b16286;background-color:#1d2021}h1,h2,h3,h4,h5{margin-bottom:.1rem}blockquote{border-left:1px solid #bdae93;margin:.5em 10px;padding:.5em 10px}footer{align:center}@media (prefers-color-scheme:light){body{background:#fbf1c7;color:#3c3836}pre{background-color:#ebdbb2;padding:1em;border:0}a,a:active,a:visited{color:#b16286;background-color:#f9f5d7}h1,h2,h3,h4,h5{margin-bottom:.1rem}blockquote{border-left:1px solid #655c54;margin:.5em 10px;padding:.5em 10px}} + </style> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + </head> + <body id="top"> + <main> + <h1>XeDN</h1> + + <p>Hi there! This server is a part of XeDN, the overengineered CDN made by <a href="https://xeiaso.net">Xe Iaso</a>. I hope you're having a good day. This server can't help you much.</p> + + <footer> + <p>CSS available under the MIT license.</p> + </footer> + </main> + </body> +</html> 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 { |
