cmd/gomuks: import frontend in main (#475)

This allows using pkg/gomuks as a library without the frontend
This commit is contained in:
batuhan 2024-11-10 16:35:23 +01:00 committed by GitHub
parent bc550cbff4
commit 05fbdaaf0e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 2 deletions

View file

@ -30,6 +30,7 @@ import (
"go.mau.fi/gomuks/pkg/gomuks" "go.mau.fi/gomuks/pkg/gomuks"
"go.mau.fi/gomuks/pkg/hicli" "go.mau.fi/gomuks/pkg/hicli"
"go.mau.fi/gomuks/web"
) )
var ( var (
@ -77,6 +78,7 @@ func main() {
gmx.Commit = Commit gmx.Commit = Commit
gmx.LinkifiedVersion = LinkifiedVersion gmx.LinkifiedVersion = LinkifiedVersion
gmx.BuildTime = ParsedBuildTime gmx.BuildTime = ParsedBuildTime
gmx.FrontendFS = web.Frontend
gmx.Run() gmx.Run()
} }

View file

@ -18,6 +18,7 @@ package gomuks
import ( import (
"context" "context"
"embed"
"fmt" "fmt"
"maps" "maps"
"net/http" "net/http"
@ -55,6 +56,8 @@ type Gomuks struct {
TempDir string TempDir string
LogDir string LogDir string
FrontendFS embed.FS
Config Config Config Config
stopOnce sync.Once stopOnce sync.Once

View file

@ -39,7 +39,6 @@ import (
"maunium.net/go/mautrix" "maunium.net/go/mautrix"
"go.mau.fi/gomuks/pkg/hicli" "go.mau.fi/gomuks/pkg/hicli"
"go.mau.fi/gomuks/web"
) )
func (gmx *Gomuks) StartServer() { func (gmx *Gomuks) StartServer() {
@ -62,7 +61,7 @@ func (gmx *Gomuks) StartServer() {
router.Handle("/debug/", http.DefaultServeMux) router.Handle("/debug/", http.DefaultServeMux)
} }
router.Handle("/_gomuks/", apiHandler) router.Handle("/_gomuks/", apiHandler)
if frontend, err := fs.Sub(web.Frontend, "dist"); err != nil { if frontend, err := fs.Sub(gmx.FrontendFS, "dist"); err != nil {
gmx.Log.Warn().Msg("Frontend not found") gmx.Log.Warn().Msg("Frontend not found")
} else { } else {
router.Handle("/", gmx.FrontendCacheMiddleware(http.FileServerFS(frontend))) router.Handle("/", gmx.FrontendCacheMiddleware(http.FileServerFS(frontend)))