From 77b3655c3c7a836fd059f2effa601de64e773e6f Mon Sep 17 00:00:00 2001 From: pathmapper Date: Thu, 23 Jul 2020 19:22:43 +0200 Subject: [PATCH 1/6] Add option to serve directory under /static/ (from #2) --- maputnik.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/maputnik.go b/maputnik.go index fc686bd..d426f82 100644 --- a/maputnik.go +++ b/maputnik.go @@ -32,6 +32,10 @@ func main() { Value: 8000, Usage: "TCP port to listen on", }, + cli.StringFlag{ + Name: "static", + Usage: "Serve directory under /static/", + } } app.Action = func(c *cli.Context) error { @@ -57,6 +61,12 @@ func main() { } } + staticDir := c.String("static") + if staticDir != "" { + h := http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir))) + router.PathPrefix("/static/").Handler(h) + } + router.PathPrefix("/").Handler(http.StripPrefix("/", gui)) loggedRouter := handlers.LoggingHandler(os.Stdout, router) corsRouter := handlers.CORS(handlers.AllowedHeaders([]string{"Content-Type"}), handlers.AllowedMethods([]string{"GET", "PUT"}), handlers.AllowedOrigins([]string{"*"}), handlers.AllowCredentials())(loggedRouter) From 698fdfc95824d0097e423c109adb4038dc19fab7 Mon Sep 17 00:00:00 2001 From: pathmapper Date: Thu, 23 Jul 2020 19:28:34 +0200 Subject: [PATCH 2/6] Fix syntax error --- maputnik.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maputnik.go b/maputnik.go index d426f82..f713806 100644 --- a/maputnik.go +++ b/maputnik.go @@ -35,7 +35,7 @@ func main() { cli.StringFlag{ Name: "static", Usage: "Serve directory under /static/", - } + }, } app.Action = func(c *cli.Context) error { From e24d390f7c198532a2bc980b4b8216d1dd1fe50d Mon Sep 17 00:00:00 2001 From: pathmapper Date: Thu, 23 Jul 2020 19:33:23 +0200 Subject: [PATCH 3/6] Fix build error --- maputnik.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maputnik.go b/maputnik.go index f713806..4b4f703 100644 --- a/maputnik.go +++ b/maputnik.go @@ -32,7 +32,7 @@ func main() { Value: 8000, Usage: "TCP port to listen on", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "static", Usage: "Serve directory under /static/", }, From 77ed14a340b7bd7d99f5912d8f8a617c9ec0b5d2 Mon Sep 17 00:00:00 2001 From: pathmapper Date: Thu, 23 Jul 2020 19:52:38 +0200 Subject: [PATCH 4/6] Update desktop version number --- maputnik.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maputnik.go b/maputnik.go index 4b4f703..ba96b0b 100644 --- a/maputnik.go +++ b/maputnik.go @@ -16,7 +16,7 @@ func main() { app := cli.NewApp() app.Name = "maputnik" app.Usage = "Server for integrating Maputnik locally" - app.Version = "Editor: 1.7.0; Desktop: 1.0.6" + app.Version = "Editor: 1.7.0; Desktop: 1.0.7" app.Flags = []cli.Flag{ &cli.StringFlag{ From 46616773879751967e43d9c4f881502d298c3827 Mon Sep 17 00:00:00 2001 From: pathmapper Date: Thu, 23 Jul 2020 20:19:33 +0200 Subject: [PATCH 5/6] Add docs --- README.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 286929d..b6b8baa 100644 --- a/README.md +++ b/README.md @@ -18,14 +18,14 @@ You can download a single binary for Linux, OSX or Windows from [the latest rele Simply start up a web server and access the Maputnik editor GUI at `localhost:8000`. -``` +```bash maputnik ``` Expose a local style file to Maputnik allowing the web based editor to save to the local filesystem. -``` +```bash maputnik --file basic-v9.json ``` @@ -33,16 +33,23 @@ Watch the local style for changes and inform the editor via web socket. This makes it possible to edit the style with a local text editor and still use Maputnik. -``` +```bash maputnik --watch --file basic-v9.json ``` Choose a local port to listen on, instead of using the default port 8000. -``` +```bash maputnik --port 8001 ``` +Specify a path to a directory which, if it exists, will be served under http://localhost:8000/static/ . +Could be used to serve sprites and glyphs. + +```bash +maputnik --static ./localFolder +``` + ### API `maputnik` exposes the configured styles via a HTTP API. From b7ef0943f423688a468c8941b9a218873b8522e5 Mon Sep 17 00:00:00 2001 From: pathmapper Date: Thu, 23 Jul 2020 20:25:24 +0200 Subject: [PATCH 6/6] Fix formatting --- maputnik.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/maputnik.go b/maputnik.go index ba96b0b..0eecee8 100644 --- a/maputnik.go +++ b/maputnik.go @@ -62,10 +62,10 @@ func main() { } staticDir := c.String("static") - if staticDir != "" { - h := http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir))) - router.PathPrefix("/static/").Handler(h) - } + if staticDir != "" { + h := http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir))) + router.PathPrefix("/static/").Handler(h) + } router.PathPrefix("/").Handler(http.StripPrefix("/", gui)) loggedRouter := handlers.LoggingHandler(os.Stdout, router)