From 4dc80ac7665fc1b4802904437066e500b22a952d Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Sun, 13 Oct 2019 21:44:20 +0200 Subject: [PATCH] Add support to configure listen address --- Dockerfile | 1 + README.md | 1 + padlockcloud/cli.go | 7 +++++++ padlockcloud/server.go | 5 ++++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index fbd3401..bccbbf2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,6 +29,7 @@ ENV PC_CONFIG_PATH="" \ PC_EMAIL_PORT="" \ PC_EMAIL_USER="" \ PC_EMAIL_PASSWORD="" \ + PC_LISTEN_ADDR="0.0.0.0" \ PC_PORT=8080 \ PC_ASSETS_PATH=${WORKDIR}/assets \ PC_TLS_CERT="" \ diff --git a/README.md b/README.md index 7ebf29a..526294d 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ Starts a Padlock Cloud server instance #### Environment Variables, Flags, Configuration File Variables | Environment Variable | Flag | Configuration File | Description | |----------------------|------------------------|----------------------|----------------------------------------------| +| `PC_LISTEN_ADDR` | `--listen` | `server.listen_addr` | Address to listen on | | `PC_PORT` | `--port` | `-p` | `server.port` | Port to listen on | | `PC_ASSETS_PATH` | `--assets-path` | `server.assets_path` | Path to assets directory | | `PC_TLS_CERT` | `--tls-cert` | `server.tls_cert` | Path to TLS certification file | diff --git a/padlockcloud/cli.go b/padlockcloud/cli.go index a437719..88975d8 100644 --- a/padlockcloud/cli.go +++ b/padlockcloud/cli.go @@ -290,6 +290,13 @@ func NewCliApp() *CliApp { Name: "runserver", Usage: "Starts a Padlock Cloud server instance", Flags: []cli.Flag{ + cli.StringFlag{ + Name: "listen-addr", + Usage: "Address to listen on", + Value: "", + EnvVar: "PC_LISTEN_ADDR", + Destination: &config.Server.ListenAddr, + }, cli.IntFlag{ Name: "port, p", Usage: "Port to listen on", diff --git a/padlockcloud/server.go b/padlockcloud/server.go index 135bbc1..76eef13 100644 --- a/padlockcloud/server.go +++ b/padlockcloud/server.go @@ -82,6 +82,8 @@ func (d *DataStore) Serialize() ([]byte, error) { type ServerConfig struct { // Path to assets directory; used for loading templates and such AssetsPath string `yaml:"assets_path"` + // Address to listen on + ListenAddr string `yaml:"listen_addr"` // Port to listen on Port int `yaml:"port"` // Path to TLS certificate @@ -580,11 +582,12 @@ func (server *Server) Start() error { server.InitHandler() + listenAddr := server.Config.ListenAddr port := server.Config.Port tlsCert := server.Config.TLSCert tlsKey := server.Config.TLSKey - server.Addr = fmt.Sprintf(":%d", port) + server.Addr = fmt.Sprintf("%s:%d", listenAddr, port) // Start server if tlsCert != "" && tlsKey != "" {