Add option to serve directory under /static/ (from #2)

This commit is contained in:
pathmapper
2020-07-23 19:22:43 +02:00
parent c264cd1771
commit 77b3655c3c

View File

@@ -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)