mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
New: Make host configurable, Fix #69
Former-commit-id: e087e6952610f7baeb212e12cef44eafcb06613d
This commit is contained in:
parent
86c86779dd
commit
23536ad927
@ -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
|
||||
|
||||
|
@ -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 {
|
||||
|
13
main.go
13
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",
|
||||
|
Loading…
Reference in New Issue
Block a user