mirror of
https://github.com/go-shiori/shiori.git
synced 2025-01-15 20:37:44 +08:00
Add flag to specify custom address
This commit is contained in:
parent
c22f904bdd
commit
806a3cff40
3 changed files with 65 additions and 63 deletions
|
@ -17,14 +17,16 @@ func serveCmd() *cobra.Command {
|
|||
}
|
||||
|
||||
cmd.Flags().IntP("port", "p", 8080, "Port that used by server")
|
||||
cmd.Flags().StringP("address", "a", "", "Address the server listens to")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func serveHandler(cmd *cobra.Command, args []string) {
|
||||
port, _ := cmd.Flags().GetInt("port")
|
||||
address, _ := cmd.Flags().GetString("address")
|
||||
|
||||
err := webserver.ServeApp(db, dataDir, port)
|
||||
err := webserver.ServeApp(db, dataDir, address, port)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Server error: %v\n", err)
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -15,7 +15,7 @@ import (
|
|||
var httpClient = &http.Client{Timeout: time.Minute}
|
||||
|
||||
// ServeApp serves wb interface in specified port
|
||||
func ServeApp(DB database.DB, dataDir string, port int) error {
|
||||
func ServeApp(DB database.DB, dataDir string, address string, port int) error {
|
||||
// Create handler
|
||||
hdl := handler{
|
||||
DB: DB,
|
||||
|
@ -68,7 +68,7 @@ func ServeApp(DB database.DB, dataDir string, port int) error {
|
|||
}
|
||||
|
||||
// Create server
|
||||
url := fmt.Sprintf(":%d", port)
|
||||
url := fmt.Sprintf("%s:%d", address, port)
|
||||
svr := &http.Server{
|
||||
Addr: url,
|
||||
Handler: router,
|
||||
|
|
Loading…
Reference in a new issue