diff --git a/internal/component/control/extras_info.go b/internal/component/control/extras_info.go index 297fbe2..0203ffd 100644 --- a/internal/component/control/extras_info.go +++ b/internal/component/control/extras_info.go @@ -2,13 +2,13 @@ package control import ( "context" - "embed" "html/template" - "io/fs" "net/http" "strings" "time" + _ "embed" + "github.com/FAU-CDI/wisski-distillery/internal/component" "github.com/FAU-CDI/wisski-distillery/internal/component/instances" "github.com/FAU-CDI/wisski-distillery/internal/config" @@ -40,13 +40,6 @@ func (info *Info) Handler(route string, context context.Context, io stream.IOStr http.NotFound(w, r) }) - // static stuff - static, err := info.disStatic() - if err != nil { - return nil, err - } - mux.Handle("/dis/static/", static) - // render everything mux.Handle("/dis/index", httpx.HTMLHandler[disIndex]{ Handler: info.disIndex, @@ -159,18 +152,6 @@ func (info *Info) disInstance(r *http.Request) (is disInstance, err error) { return } -//go:embed html/static -var htmlStaticFS embed.FS - -func (*Info) disStatic() (http.Handler, error) { - fs, err := fs.Sub(htmlStaticFS, "html/static") - if err != nil { - return nil, err - } - - return http.StripPrefix("/dis/static/", http.FileServer(http.FS(fs))), nil -} - //go:embed "html/index.html" var indexTemplateStr string var indexTemplate = template.Must(template.New("index.html").Parse(indexTemplateStr)) diff --git a/internal/component/control/html/index.html b/internal/component/control/html/index.html index 7e52a1a..b756697 100644 --- a/internal/component/control/html/index.html +++ b/internal/component/control/html/index.html @@ -1,6 +1,6 @@ - - + +
{{ .Time }}
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/internal/component/control/html/instance.html b/internal/component/control/html/instance.html
index 6ef2b82..c62f53f 100644
--- a/internal/component/control/html/instance.html
+++ b/internal/component/control/html/instance.html
@@ -1,6 +1,6 @@
-
-
+
+
{{ .Time }}
-
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/internal/component/control/html/static/autolink.css b/internal/component/static/out/control/autolink.css
similarity index 100%
rename from internal/component/control/html/static/autolink.css
rename to internal/component/static/out/control/autolink.css
diff --git a/internal/component/control/html/static/autolink.js b/internal/component/static/out/control/autolink.js
similarity index 100%
rename from internal/component/control/html/static/autolink.js
rename to internal/component/static/out/control/autolink.js
diff --git a/internal/component/control/html/static/dis.css b/internal/component/static/out/control/dis.css
similarity index 100%
rename from internal/component/control/html/static/dis.css
rename to internal/component/static/out/control/dis.css
diff --git a/internal/component/control/html/static/instance.js b/internal/component/static/out/control/instance.js
similarity index 100%
rename from internal/component/control/html/static/instance.js
rename to internal/component/static/out/control/instance.js
diff --git a/internal/component/static/static.go b/internal/component/static/static.go
new file mode 100644
index 0000000..6e91b11
--- /dev/null
+++ b/internal/component/static/static.go
@@ -0,0 +1,32 @@
+// Package static implements serving of fully static resources
+package static
+
+import (
+ "context"
+ "embed"
+ "io/fs"
+ "net/http"
+
+ "github.com/FAU-CDI/wisski-distillery/internal/component"
+ "github.com/tkw1536/goprogram/stream"
+)
+
+type Static struct {
+ component.ComponentBase
+}
+
+func (*Static) Name() string { return "static" }
+
+func (*Static) Routes() []string { return []string{"/static/"} }
+
+func (static *Static) Handler(route string, context context.Context, io stream.IOStream) (http.Handler, error) {
+ fs, err := fs.Sub(htmlStaticFS, "out")
+ if err != nil {
+ return nil, err
+ }
+
+ return http.StripPrefix(route, http.FileServer(http.FS(fs))), nil
+}
+
+//go:embed out
+var htmlStaticFS embed.FS
diff --git a/internal/dis/component.go b/internal/dis/component.go
index 094ce71..751c7e9 100644
--- a/internal/dis/component.go
+++ b/internal/dis/component.go
@@ -11,6 +11,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/component/snapshots"
"github.com/FAU-CDI/wisski-distillery/internal/component/sql"
"github.com/FAU-CDI/wisski-distillery/internal/component/ssh"
+ "github.com/FAU-CDI/wisski-distillery/internal/component/static"
"github.com/FAU-CDI/wisski-distillery/internal/component/triplestore"
"github.com/FAU-CDI/wisski-distillery/internal/component/web"
)
@@ -44,6 +45,7 @@ func (dis *Distillery) register(context *component.PoolContext) []component.Comp
// Control server
ra[*control.Control](dis, context),
+ ra[*static.Static](dis, context),
r(dis, context, func(home *home.Home) {
home.RefreshInterval = time.Minute
}),