feat(m4): SvelteKit frontend - today, week, history, settings views
This commit is contained in:
9
cmd/wotra/embed_dev.go
Normal file
9
cmd/wotra/embed_dev.go
Normal file
@@ -0,0 +1,9 @@
|
||||
// embed_dev.go — used in non-production builds (no web/build directory required)
|
||||
//go:build !production
|
||||
|
||||
package main
|
||||
|
||||
import "io/fs"
|
||||
|
||||
// webFS is nil in dev mode; the router will skip static file serving.
|
||||
var webFS fs.FS
|
||||
20
cmd/wotra/embed_prod.go
Normal file
20
cmd/wotra/embed_prod.go
Normal file
@@ -0,0 +1,20 @@
|
||||
// embed_prod.go — used in production builds (requires web/build to exist)
|
||||
//go:build production
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
)
|
||||
|
||||
//go:embed all:../../web/build
|
||||
var embeddedWeb embed.FS
|
||||
|
||||
var webFS fs.FS = func() fs.FS {
|
||||
sub, err := fs.Sub(embeddedWeb, "web/build")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return sub
|
||||
}()
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/fs"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -53,7 +54,13 @@ func main() {
|
||||
defer cancel()
|
||||
go runMidnightGuard(ctx, entrySvc)
|
||||
|
||||
router := handler.NewRouter(cfg.AuthToken, entrySvc, daySvc, settingsSvc, weekSvc)
|
||||
// Static SPA files (embedded or from disk for dev)
|
||||
var staticFS fs.FS
|
||||
if webFS != nil {
|
||||
staticFS = webFS
|
||||
}
|
||||
|
||||
router := handler.NewRouter(cfg.AuthToken, entrySvc, daySvc, settingsSvc, weekSvc, staticFS)
|
||||
|
||||
srv := &http.Server{
|
||||
Addr: ":" + cfg.Port,
|
||||
|
||||
Reference in New Issue
Block a user