mirror of
https://github.com/maputnik/editor.git
synced 2026-08-25 06:27:25 +00:00
Add websocket filewatcher
This commit is contained in:
+30
-1
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/gorilla/handlers"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/maputnik/desktop/filewatch"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@@ -14,11 +15,39 @@ func main() {
|
||||
app.Name = "maputnik"
|
||||
app.Usage = "Server for integrating Maputnik locally"
|
||||
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "file, f",
|
||||
Usage: "Allow access to JSON style from web client",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "watch",
|
||||
Usage: "Notify web client about JSON style file changes",
|
||||
},
|
||||
}
|
||||
|
||||
app.Action = func(c *cli.Context) error {
|
||||
gui := http.FileServer(assetFS())
|
||||
|
||||
router := mux.NewRouter().StrictSlash(true)
|
||||
//router.Path("/api/v1/apps").Methods("GET").HandlerFunc(foo)
|
||||
|
||||
// Register websocket to notify we clients about file changes
|
||||
filename := c.String("file")
|
||||
|
||||
if filename != "" {
|
||||
/*
|
||||
router.Path("/files").Methods("GET").HandlerFunc(listFiles)
|
||||
router.Path("/files/{filename}").Methods("PUT").HandlerFunc(saveFile)
|
||||
*/
|
||||
|
||||
if c.Bool("watch") {
|
||||
router.Path("/ws").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
filewatch.ServeWebsocketFileWatcher(filename, w, r)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
router.PathPrefix("/").Handler(http.StripPrefix("/", gui))
|
||||
|
||||
loggedRouter := handlers.LoggingHandler(os.Stdout, router)
|
||||
|
||||
Reference in New Issue
Block a user