Skip to content

Commit

Permalink
Allow override JS bundle path for development (#704)
Browse files Browse the repository at this point in the history
* Allow override JS bundle path for development

* Make linter happy
  • Loading branch information
raphael committed May 9, 2024
1 parent 3e23f9d commit 5db21dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions cmd/mdl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func main() {
port = svrset.Int("port", 8080, "set local HTTP port used to serve diagram editor")

devmode = os.Getenv("DEVMODE") == "1"
devdist = os.Getenv("DEVDIST")

showUsage = func() { printUsage(svrset, genset, gset) }
)
Expand Down Expand Up @@ -99,7 +100,10 @@ func main() {
if err := os.MkdirAll(*dir, 0700); err != nil {
fail(err.Error())
}
err = serve(*dir, pkg, *port, devmode, *debug)
if devmode && devdist == "" {
devdist = "./cmd/mdl/webapp/dist"
}
err = serve(*dir, pkg, *port, devdist, *debug)
case "version":
fmt.Printf("%s %s\n", os.Args[0], model.Version())
case "", "help":
Expand All @@ -112,7 +116,7 @@ func main() {
}
}

func serve(out, pkg string, port int, devmode, debug bool) error {
func serve(out, pkg string, port int, devdist string, debug bool) error {
// Retrieve initial design and create server.
b, err := codegen.JSON(pkg, debug)
if err != nil {
Expand Down Expand Up @@ -142,7 +146,7 @@ func serve(out, pkg string, port int, devmode, debug bool) error {
return err
}

return s.Serve(out, devmode, port)
return s.Serve(out, devdist, port)
}

func printUsage(fss ...*flag.FlagSet) {
Expand Down
8 changes: 4 additions & 4 deletions cmd/mdl/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ var distFS embed.FS
// indicates where the view data structures are located. If devmode is true then
// the single page app is served directly from the source under the "webapp"
// directory. Otherwise, it is served from the code embedded in the Go executable.
func (s *Server) Serve(outDir string, devmode bool, port int) error {
func (s *Server) Serve(outDir, devDistPath string, port int) error {

if devmode {
// in devmode (go run), serve the webapp from filesystem
fs := http.FileSystem(http.Dir("./cmd/mdl/webapp/dist"))
if devDistPath != "" {
// in devmode, serve the webapp from filesystem
fs := http.FileSystem(http.Dir(devDistPath))
http.Handle("/", http.FileServer(fs))
} else {
sub, _ := fs.Sub(distFS, "webapp/dist")
Expand Down

0 comments on commit 5db21dc

Please sign in to comment.