aboutsummaryrefslogtreecommitdiff
path: root/cmd/web/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/web/main.go')
-rw-r--r--cmd/web/main.go36
1 files changed, 34 insertions, 2 deletions
diff --git a/cmd/web/main.go b/cmd/web/main.go
index d66e366..091d22f 100644
--- a/cmd/web/main.go
+++ b/cmd/web/main.go
@@ -2,6 +2,7 @@ package main
import (
"flag"
+ "io"
"fmt"
"log"
"math/rand"
@@ -11,6 +12,7 @@ import (
"strings"
"sync"
"time"
+ "embed"
"github.com/gorilla/mux"
"riedstra.dev/mitch/steam-export/steam"
@@ -26,6 +28,9 @@ var (
Logger = log.New(os.Stderr, "", log.LstdFlags)
Listen = ":8899"
+ //go:embed static/*
+ embeddedStatic embed.FS
+
Lib steamLib
)
@@ -60,6 +65,33 @@ func setLibHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", 302)
}
+func staticHandler(w http.ResponseWriter, r *http.Request){
+ /*
+ vars := mux.Vars(r)
+
+ fn, ok := vars["fn"]
+ if !ok {
+ http.Error(w, "Not found", http.StatusNotFound)
+ return
+ }
+ */
+
+ fn := r.URL.Path
+
+ fh, err := embeddedStatic.Open(fn)
+ if err != nil {
+ Logger.Printf("While reading embedded file: %s", err)
+ http.Error(w, "Not found", http.StatusNotFound)
+ return
+ }
+ defer fh.Close()
+
+ _, err = io.Copy(w, fh)
+ if err != nil {
+ Logger.Printf("While sending static file: %s", err)
+ }
+}
+
func quitHandler(w http.ResponseWriter, r *http.Request) {
if unauthorizedIfNotLocal(w, r) {
return
@@ -163,8 +195,8 @@ func main() {
r.HandleFunc("/steam-export-web.exe", serveSelf)
r.HandleFunc("/download/{game}", gameDownloader)
r.HandleFunc("/status", statsHandler)
- r.HandleFunc("/style.css", cssHandler)
- r.HandleFunc("/main.js", jsHandler)
+ r.PathPrefix("/static").Handler(
+ http.FileServer(http.FS(embeddedStatic)))
r.HandleFunc("/", index)
s := http.Server{