From 23536ad9272e4ab310aa8e17b3bf77ddf46e1d1d Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Tue, 28 Mar 2017 08:01:03 -0600 Subject: [PATCH] New: Make host configurable, Fix #69 Former-commit-id: e087e6952610f7baeb212e12cef44eafcb06613d --- README.md | 2 +- handlers.go | 4 ++-- main.go | 13 +++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f301831..a7022f1 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ To run just double click or from the command line: cowyo ``` -and it will start a server listening on `0.0.0.0:8050`. To view it, just go to http://localhost:8050 (the server prints out the local IP for your info if you want to do LAN networking). You can change the port with `-port X`. +and it will start a server listening on `0.0.0.0:8050`. To view it, just go to http://localhost:8050 (the server prints out the local IP for your info if you want to do LAN networking). You can change the port with `-port X`, and you can listen *only* on localhost using `-host localhost`. ## Usage diff --git a/handlers.go b/handlers.go index 6c26254..e2476db 100755 --- a/handlers.go +++ b/handlers.go @@ -12,7 +12,7 @@ import ( "github.com/gin-gonic/gin" ) -func serve(port string) { +func serve(host, port string) { gin.SetMode(gin.ReleaseMode) router := gin.Default() router.HTMLRender = loadTemplates("index.tmpl") @@ -32,7 +32,7 @@ func serve(port string) { router.DELETE("/oldlist", handleClearOldListItems) router.DELETE("/listitem", deleteListItem) - router.Run(":" + port) + router.Run(host + ":" + port) } func loadTemplates(list ...string) multitemplate.Render { diff --git a/main.go b/main.go index c8795d2..214bb9a 100755 --- a/main.go +++ b/main.go @@ -23,8 +23,12 @@ func main() { } pathToData = c.GlobalString("data") os.MkdirAll(pathToData, 0755) - fmt.Printf("\nRunning cowyo server (version %s) at http://%s:%s\n\n", version, GetLocalIP(), c.GlobalString("port")) - serve(c.GlobalString("port")) + host := c.GlobalString("host") + if host == "" { + host = GetLocalIP() + } + fmt.Printf("\nRunning cowyo server (version %s) at http://%s:%s\n\n", version, host, c.GlobalString("port")) + serve(c.GlobalString("host"), c.GlobalString("port")) return nil } app.Flags = []cli.Flag{ @@ -38,6 +42,11 @@ func main() { Value: "", Usage: "data folder for migrating", }, + cli.StringFlag{ + Name: "host", + Value: "", + Usage: "host to use", + }, cli.StringFlag{ Name: "port,p", Value: "8050",