1
0
Fork 0
forked from Mirrors/gomuks

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/hicli"
"go.mau.fi/gomuks/web"
)
var (
@ -77,6 +78,7 @@ func main() {
gmx.Commit = Commit
gmx.LinkifiedVersion = LinkifiedVersion
gmx.BuildTime = ParsedBuildTime
gmx.FrontendFS = web.Frontend
gmx.Run()
}

View file

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

View file

@ -39,7 +39,6 @@ import (
"maunium.net/go/mautrix"
"go.mau.fi/gomuks/pkg/hicli"
"go.mau.fi/gomuks/web"
)
func (gmx *Gomuks) StartServer() {
@ -62,7 +61,7 @@ func (gmx *Gomuks) StartServer() {
router.Handle("/debug/", http.DefaultServeMux)
}
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")
} else {
router.Handle("/", gmx.FrontendCacheMiddleware(http.FileServerFS(frontend)))