mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-20 10:33:41 -05:00
cmd/gomuks: import frontend in main (#475)
This allows using pkg/gomuks as a library without the frontend
This commit is contained in:
parent
bc550cbff4
commit
05fbdaaf0e
3 changed files with 6 additions and 2 deletions
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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)))
|
||||||
|
|
Loading…
Add table
Reference in a new issue