From 375eab8e22a1a347f985f4cb5e1ad6e56ba86a35 Mon Sep 17 00:00:00 2001 From: Robert Janetzko Date: Mon, 9 May 2022 15:20:31 +0000 Subject: [PATCH] command line arguments --- backend/cmd/root.go | 1 + backend/go.mod | 3 + backend/go.sum | 10 +++ backend/main.go | 105 +++++++++++++++++++----------- backend/model/collections.go | 2 +- backend/model/context.go | 36 +++++----- backend/server/config.go | 7 +- backend/server/loading.go | 14 +++- backend/server/server.go | 12 ++-- backend/server/static.go | 7 +- backend/server/templates.go | 3 +- backend/server/util.go | 2 +- backend/static/js/map.js | 4 +- backend/templates/eventTypes.html | 2 +- backend/templates/events.html | 2 +- backend/templates/hfs.html | 4 +- backend/templates/layout.html | 60 ++++++++--------- backend/templates/load.html | 8 +-- backend/templates/loading.html | 2 +- backend/templates/serverMode.html | 8 +++ backend/templates/years.html | 2 +- 21 files changed, 183 insertions(+), 111 deletions(-) create mode 100644 backend/cmd/root.go create mode 100644 backend/templates/serverMode.html diff --git a/backend/cmd/root.go b/backend/cmd/root.go new file mode 100644 index 0000000..1d619dd --- /dev/null +++ b/backend/cmd/root.go @@ -0,0 +1 @@ +package cmd diff --git a/backend/go.mod b/backend/go.mod index 8b84ada..8a50307 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -9,6 +9,7 @@ require ( github.com/iancoleman/strcase v0.2.0 github.com/pkg/profile v1.6.0 github.com/shirou/gopsutil v3.21.11+incompatible + github.com/spf13/cobra v1.4.0 golang.org/x/exp v0.0.0-20220428152302-39d4317da171 golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 ) @@ -17,10 +18,12 @@ require ( github.com/VividCortex/ewma v1.1.1 // indirect github.com/fatih/color v1.10.0 // indirect github.com/go-ole/go-ole v1.2.6 // indirect + github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/mattn/go-colorable v0.1.8 // indirect github.com/mattn/go-isatty v0.0.12 // indirect github.com/mattn/go-runewidth v0.0.12 // indirect github.com/rivo/uniseg v0.2.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect github.com/yusufpapurcu/wmi v1.2.2 // indirect golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect ) diff --git a/backend/go.sum b/backend/go.sum index 9135d9c..8351a04 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -2,6 +2,7 @@ github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdc github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA= github.com/cheggaaa/pb/v3 v3.0.8 h1:bC8oemdChbke2FHIIGy9mn4DPJ2caZYQnfbRqwmdCoA= github.com/cheggaaa/pb/v3 v3.0.8/go.mod h1:UICbiLec/XO6Hw6k+BHEtHeQFzzBH4i2/qk/ow1EJTA= +github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= @@ -12,6 +13,8 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= @@ -23,8 +26,13 @@ github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdL github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q= +github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= golang.org/x/exp v0.0.0-20220428152302-39d4317da171 h1:TfdoLivD44QwvssI9Sv1xwa5DcL5XQr4au4sZ2F2NV4= @@ -39,3 +47,5 @@ golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16C golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/backend/main.go b/backend/main.go index 19cdc7e..9aa2e4d 100644 --- a/backend/main.go +++ b/backend/main.go @@ -2,62 +2,89 @@ package main import ( "embed" - "flag" "fmt" "log" "net/http" _ "net/http/pprof" + "os" "runtime" "github.com/pkg/profile" "github.com/robertjanetzko/LegendsBrowser2/backend/model" "github.com/robertjanetzko/LegendsBrowser2/backend/server" "github.com/robertjanetzko/LegendsBrowser2/backend/templates" + "github.com/spf13/cobra" ) //go:embed static var static embed.FS -func main() { - f := flag.String("f", "", "open a file") - p := flag.Bool("p", false, "start profiling") - c := flag.String("c", "", "config file") - l := flag.Bool("l", false, "open last file") - flag.Parse() +var ( + f, c, subUri string + l, p, d, s *bool + port *int +) - if *p { - defer profile.Start(profile.ProfilePath(".")).Stop() - go func() { - http.ListenAndServe(":8081", nil) - }() - } - - config, err := server.LoadConfig(*c) - if err != nil { - log.Fatal(err) - } - - server.DebugJSON = config.DebugJSON - templates.DebugTemplates = config.DebugTemplates - - var world *model.DfWorld - - if *l { - *f = config.LastFile - } - - if len(*f) > 0 { - w, err := model.Parse(*f, nil) - if err != nil { - fmt.Println(err) - } else { - runtime.GC() - world = w +var rootCmd = &cobra.Command{ + Use: "legendsbrowser", + Short: "A Legends Browser for Dwarf Fortress", + Run: func(cmd *cobra.Command, args []string) { + if *p { + defer profile.Start(profile.ProfilePath(".")).Stop() + go func() { + http.ListenAndServe(":8081", nil) + }() } - } - err = server.StartServer(config, world, static) - if err != nil { - log.Fatal(err) + config, err := server.LoadConfig(c) + if err != nil { + log.Fatal(err) + } + + templates.DebugTemplates = config.DebugTemplates + + server.DebugJSON = *d + config.Port = *port + config.ServerMode = *s + config.SubUri = subUri + + var world *model.DfWorld + + if *l { + f = config.LastFile + } + + if len(f) > 0 { + w, err := model.Parse(f, nil) + if err != nil { + fmt.Println(err) + } else { + runtime.GC() + world = w + } + } + + err = server.StartServer(config, world, static) + if err != nil { + log.Fatal(err) + } + }, +} + +func main() { + if err := rootCmd.Execute(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) } } + +func init() { + rootCmd.PersistentFlags().StringVarP(&f, "world", "w", "", "path to legends.xml") + rootCmd.PersistentFlags().StringVarP(&c, "config", "c", "", "config file") + rootCmd.PersistentFlags().StringVarP(&subUri, "subUri", "u", "", "run on /") + l = rootCmd.PersistentFlags().BoolP("last", "l", false, "open last file") + p = rootCmd.PersistentFlags().BoolP("profile", "P", false, "start profiling") + d = rootCmd.PersistentFlags().BoolP("debug", "d", false, "show debug data") + s = rootCmd.PersistentFlags().BoolP("serverMode", "s", false, "run in server mode (disables file chooser)") + port = rootCmd.PersistentFlags().IntP("port", "p", 58881, "use specific port") +} diff --git a/backend/model/collections.go b/backend/model/collections.go index c714ad5..7332195 100644 --- a/backend/model/collections.go +++ b/backend/model/collections.go @@ -9,7 +9,7 @@ import ( ) func (x *HistoricalEventCollection) Link(s string) string { - return fmt.Sprintf(`%s`, strcase.ToKebab(x.Details.Type()), x.Id_, util.Title(s)) + return fmt.Sprintf(`%s`, strcase.ToKebab(x.Details.Type()), x.Id_, util.Title(s)) } func (x *HistoricalEventCollection) ParentId() int { diff --git a/backend/model/context.go b/backend/model/context.go index 4a9a62c..b811f90 100644 --- a/backend/model/context.go +++ b/backend/model/context.go @@ -57,7 +57,7 @@ func (c *Context) hfUnrelated(id int) string { func (c *Context) hfShort(id int) string { if x, ok := c.World.HistoricalFigures[id]; ok { - return fmt.Sprintf(`%s%s`, x.Id(), hfIcon(x), util.Title(x.FirstName())) + return fmt.Sprintf(`%s%s`, x.Id(), hfIcon(x), util.Title(x.FirstName())) } return "UNKNOWN HISTORICAL FIGURE" } @@ -73,7 +73,7 @@ func (c *Context) hfRelated(id, to int) string { if x, ok := c.World.HistoricalFigures[id]; ok { if t, ok := c.World.HistoricalFigures[to]; ok { if y, ok := util.Find(t.HfLink, func(l *HfLink) bool { return l.Hfid == id }); ok { - return fmt.Sprintf(`%s %s %s%s`, t.PossesivePronoun(), y.LinkType, x.Id(), hfIcon(x), util.Title(x.Name())) + return fmt.Sprintf(`%s %s %s%s`, t.PossesivePronoun(), y.LinkType, x.Id(), hfIcon(x), util.Title(x.Name())) } } return hf(x) @@ -121,7 +121,7 @@ func hf(x *HistoricalFigure) string { if x.Vampire { r += " vampire" } - return fmt.Sprintf(`the %s %s%s`, r, x.Id(), hfIcon(x), util.Title(x.Name())) + return fmt.Sprintf(`the %s %s%s`, r, x.Id(), hfIcon(x), util.Title(x.Name())) } func (c *Context) hfList(ids []int) string { @@ -134,7 +134,7 @@ func (c *Context) hfListRelated(ids []int, to int) string { func (c *Context) artifact(id int) string { if x, ok := c.World.Artifacts[id]; ok { - return fmt.Sprintf(` %s`, x.Id(), x.Icon(), util.Title(x.Name())) + return fmt.Sprintf(` %s`, x.Id(), x.Icon(), util.Title(x.Name())) } return "UNKNOWN ARTIFACT" } @@ -145,7 +145,7 @@ func (c *Context) entity(id int) string { if c != "" { c = fmt.Sprintf(` style="color:%s"`, c) } - return fmt.Sprintf(` %s`, x.Id(), x.Icon(), c, util.Title(x.Name())) + return fmt.Sprintf(` %s`, x.Id(), x.Icon(), c, util.Title(x.Name())) } return "UNKNOWN ENTITY" } @@ -179,7 +179,7 @@ func (c *Context) siteStructure(siteId, structureId int, prefix string) string { func (c *Context) site(id int, prefix string) string { if x, ok := c.World.Sites[id]; ok { - return fmt.Sprintf(`%s %s`, prefix, x.Id(), x.Icon(), util.If(x.Ruin, " ruin", ""), util.Title(x.Name())) + return fmt.Sprintf(`%s %s`, prefix, x.Id(), x.Icon(), util.If(x.Ruin, " ruin", ""), util.Title(x.Name())) } return "UNKNOWN SITE" } @@ -187,7 +187,7 @@ func (c *Context) site(id int, prefix string) string { func (c *Context) structure(siteId, structureId int) string { if x, ok := c.World.Sites[siteId]; ok { if y, ok := x.Structures[structureId]; ok { - return fmt.Sprintf(` %s`, siteId, structureId, y.Icon(), util.If(y.Ruin, " ruin", ""), util.Title(y.Name())) + return fmt.Sprintf(` %s`, siteId, structureId, y.Icon(), util.If(y.Ruin, " ruin", ""), util.Title(y.Name())) } } return "UNKNOWN STRUCTURE" @@ -207,7 +207,7 @@ func (c *Context) property(siteId, propertyId int) string { func (c *Context) region(id int) string { if x, ok := c.World.Regions[id]; ok { - return fmt.Sprintf(`%s`, x.Id(), util.Title(x.Name())) + return fmt.Sprintf(`%s`, x.Id(), util.Title(x.Name())) } return "UNKNOWN REGION" } @@ -234,7 +234,7 @@ func (c *Context) place(structureId, siteId int, sitePrefix string, regionId int func (c *Context) mountain(id int) string { if x, ok := c.World.MountainPeaks[id]; ok { - return fmt.Sprintf(` %s`, + return fmt.Sprintf(` %s`, x.Id(), util.If(x.IsVolcano, "fa-volcano", "fa-mountain"), util.Title(x.Name())) } return "UNKNOWN MOUNTAIN" @@ -242,61 +242,61 @@ func (c *Context) mountain(id int) string { func (c *Context) landmass(id int) string { if x, ok := c.World.Landmasses[id]; ok { - return fmt.Sprintf(`%s`, x.Id(), util.Title(x.Name())) + return fmt.Sprintf(`%s`, x.Id(), util.Title(x.Name())) } return "UNKNOWN LANDMASS" } func (c *Context) river(id int) string { x := c.World.Rivers[id] - return fmt.Sprintf(`%s`, id, util.Title(x.Name())) + return fmt.Sprintf(`%s`, id, util.Title(x.Name())) } func (c *Context) identity(id int) string { if x, ok := c.World.Identities[id]; ok { - return fmt.Sprintf(`%s`, x.Id(), util.Title(x.Name())) + return fmt.Sprintf(`%s`, x.Id(), util.Title(x.Name())) } return "UNKNOWN IDENTITY" } func (c *Context) fullIdentity(id int) string { if x, ok := c.World.Identities[id]; ok { - return fmt.Sprintf(`"the %s %s of %s"`, x.Profession.String(), x.Id(), util.Title(x.Name()), c.entity(x.EntityId)) + return fmt.Sprintf(`"the %s %s of %s"`, x.Profession.String(), x.Id(), util.Title(x.Name()), c.entity(x.EntityId)) } return "UNKNOWN IDENTITY" } func (c *Context) danceForm(id int) string { if x, ok := c.World.DanceForms[id]; ok { - return fmt.Sprintf(` %s`, id, util.Title(x.Name())) + return fmt.Sprintf(` %s`, id, util.Title(x.Name())) } return "UNKNOWN DANCE FORM" } func (c *Context) musicalForm(id int) string { if x, ok := c.World.MusicalForms[id]; ok { - return fmt.Sprintf(` %s`, id, util.Title(x.Name())) + return fmt.Sprintf(` %s`, id, util.Title(x.Name())) } return "UNKNOWN MUSICAL FORM" } func (c *Context) poeticForm(id int) string { if x, ok := c.World.PoeticForms[id]; ok { - return fmt.Sprintf(` %s`, id, util.Title(x.Name())) + return fmt.Sprintf(` %s`, id, util.Title(x.Name())) } return "UNKNOWN POETIC FORM" } func (c *Context) worldConstruction(id int) string { if x, ok := c.World.WorldConstructions[id]; ok { - return fmt.Sprintf(` %s`, id, x.Icon(), util.Title(x.Name())) + return fmt.Sprintf(` %s`, id, x.Icon(), util.Title(x.Name())) } return "UNKNOWN WORLD CONSTRUCTION" } func (c *Context) writtenContent(id int) string { if x, ok := c.World.WrittenContents[id]; ok { - return fmt.Sprintf(`%s`, id, util.Title(x.Name())) + return fmt.Sprintf(`%s`, id, util.Title(x.Name())) } return "UNKNOWN WORLD CONSTRUCTION" } diff --git a/backend/server/config.go b/backend/server/config.go index dc313d6..9a7b6df 100644 --- a/backend/server/config.go +++ b/backend/server/config.go @@ -12,8 +12,11 @@ type Config struct { path string LastPath string LastFile string - DebugTemplates bool `json:"DebugTemplates,omitempty"` - DebugJSON bool `json:"DebugJSON,omitempty"` + Port int `json:"-"` + ServerMode bool `json:"-"` + SubUri string `json:"-"` + DebugTemplates bool `json:"DebugTemplates,omitempty"` + DebugJSON bool `json:"DebugJSON,omitempty"` } func LoadConfig(path string) (*Config, error) { diff --git a/backend/server/loading.go b/backend/server/loading.go index 44b5e5e..b325e1c 100644 --- a/backend/server/loading.go +++ b/backend/server/loading.go @@ -48,6 +48,14 @@ func (h loadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } + if h.server.context.config.ServerMode { + err := h.server.templates.Render(w, "serverMode.html", nil) + if err != nil { + httpError(w, err) + } + return + } + var partitions []string if runtime.GOOS == "windows" { ps, _ := disk.Partitions(false) @@ -95,11 +103,11 @@ func (h loadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { h.server.context.isLoading = true h.server.context.world = nil go loadWorld(h.server, p.Current) - http.Redirect(w, r, "/", http.StatusSeeOther) + http.Redirect(w, r, h.server.context.config.SubUri+"/", http.StatusSeeOther) return } } - http.Redirect(w, r, "/load", http.StatusSeeOther) + http.Redirect(w, r, h.server.context.config.SubUri+"/load", http.StatusSeeOther) } func isLegendsXml(f fs.FileInfo) bool { @@ -126,6 +134,6 @@ func (srv *DfServer) renderLoading(w http.ResponseWriter, r *http.Request) { httpError(w, err) } } else { - http.Redirect(w, r, "/load", http.StatusSeeOther) + http.Redirect(w, r, srv.context.config.SubUri+"/load", http.StatusSeeOther) } } diff --git a/backend/server/server.go b/backend/server/server.go index d6dc7be..176b1a7 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -39,6 +39,12 @@ func StartServer(config *Config, world *model.DfWorld, static embed.FS) error { progress: &model.LoadProgress{}, }, } + + root := srv.router + if srv.context.config.SubUri != "" { + srv.router = srv.router.PathPrefix("/legends").Subrouter() + } + srv.loader = &loadHandler{server: srv} srv.LoadTemplates() @@ -196,10 +202,8 @@ func StartServer(config *Config, world *model.DfWorld, static embed.FS) error { } srv.router.PathPrefix("/").Handler(spa) - OpenBrowser("http://localhost:8080") - - fmt.Println("Serving at :8080") - http.ListenAndServe(":8080", srv.router) + OpenBrowser(fmt.Sprintf("http://localhost:%d", config.Port)) + http.ListenAndServe(fmt.Sprintf(":%d", config.Port), root) return nil } diff --git a/backend/server/static.go b/backend/server/static.go index 15fb699..bc1ed24 100644 --- a/backend/server/static.go +++ b/backend/server/static.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "net/http" "os" + "strings" ) type spaHandler struct { @@ -18,6 +19,7 @@ type spaHandler struct { func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // get the absolute path to prevent directory traversal path := r.URL.Path + path = strings.TrimPrefix(path, h.server.context.config.SubUri) // if err != nil { // // if we failed to get the absolute path respond with a 400 bad request and stop // http.Error(w, err.Error(), http.StatusBadRequest) @@ -26,8 +28,11 @@ func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // prepend the path with the path to the static directory path = h.staticPath + path + fmt.Println(path) + _, err := h.staticFS.Open(path) if os.IsNotExist(err) { + fmt.Println("ERR") // file does not exist, serve index.html fmt.Println(path) file, err := h.staticFS.Open(h.staticPath + "/" + h.indexPath) @@ -57,5 +62,5 @@ func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // otherwise, use http.FileServer to serve the static dir - http.FileServer(http.FS(statics)).ServeHTTP(w, r) + http.StripPrefix(h.server.context.config.SubUri, http.FileServer(http.FS(statics))).ServeHTTP(w, r) } diff --git a/backend/server/templates.go b/backend/server/templates.go index e591ce4..a2e3380 100644 --- a/backend/server/templates.go +++ b/backend/server/templates.go @@ -32,10 +32,11 @@ func (srv *DfServer) LoadTemplates() { "title": util.Title, "kebab": func(s string) string { return strcase.ToKebab(s) }, "andList": model.AndList, + "suburi": func() string { return srv.context.config.SubUri }, "world": func() *model.DfWorld { return srv.context.world }, "context": func(r any) *model.Context { return model.NewContext(srv.context.world, r) }, "initMap": func() template.HTML { - return template.HTML(fmt.Sprintf(``, + return template.HTML(fmt.Sprintf(``, srv.context.world.Width, srv.context.world.Height)) }, "hf": func(id int) template.HTML { return model.LinkHf(srv.context.world, id) }, diff --git a/backend/server/util.go b/backend/server/util.go index 8608d28..d47bc9c 100644 --- a/backend/server/util.go +++ b/backend/server/util.go @@ -21,7 +21,7 @@ func OpenBrowser(url string) { } if err != nil { fmt.Println(err) - fmt.Println("navigate to http://localhost:8080 in your browser") + fmt.Println("navigate to " + url + " in your browser") } } diff --git a/backend/static/js/map.js b/backend/static/js/map.js index 74268ea..c3af428 100644 --- a/backend/static/js/map.js +++ b/backend/static/js/map.js @@ -49,7 +49,7 @@ map.fitBounds(bounds); map.options.minZoom = map.getZoom(); -var imageUrl = '/map' +var imageUrl = './map' var imageBounds = [[0, 0], [worldWidth, worldHeight]]; @@ -106,7 +106,7 @@ function attachTooltip(layer, tip) { function urlToolTip(type, id) { return function (layer) { return $.ajax({ - url: "/popover/" + type + "/" + id, + url: "./popover/" + type + "/" + id, async: false }).responseText; } diff --git a/backend/templates/eventTypes.html b/backend/templates/eventTypes.html index fc12f8e..6b30a9a 100644 --- a/backend/templates/eventTypes.html +++ b/backend/templates/eventTypes.html @@ -5,7 +5,7 @@ {{define "content"}} {{- end }} \ No newline at end of file diff --git a/backend/templates/events.html b/backend/templates/events.html index ba12e1f..c160c80 100644 --- a/backend/templates/events.html +++ b/backend/templates/events.html @@ -3,7 +3,7 @@
  • In {{ time $event.Year $event.Seconds72 }}, {{ html ($event.Details.Html ($.Context.WithEvent $event)) }} - {{ if ne .Collection -1 }} {{end}} {{ json $event.Details }}
  • diff --git a/backend/templates/hfs.html b/backend/templates/hfs.html index 3117319..e9b3467 100644 --- a/backend/templates/hfs.html +++ b/backend/templates/hfs.html @@ -18,7 +18,7 @@ {{- range .Hfs }}{{- if not (eq .Name "") }} - {{ title .Name }} + {{ title .Name }} {{ .Race }} {{- if eq .DeathYear -1 }} @@ -34,7 +34,7 @@
    Filter
    -
    +