From 77b3655c3c7a836fd059f2effa601de64e773e6f Mon Sep 17 00:00:00 2001 From: pathmapper Date: Thu, 23 Jul 2020 19:22:43 +0200 Subject: [PATCH] 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 fc686bda..d426f827 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)