@@ -11,9 +11,9 @@ import (
11
11
"github.com/jsiebens/ionscale/internal/util"
12
12
"github.com/mitchellh/go-homedir"
13
13
"gopkg.in/yaml.v3"
14
+ "net/url"
14
15
"os"
15
16
"path/filepath"
16
- "strings"
17
17
tkey "tailscale.com/types/key"
18
18
"time"
19
19
)
@@ -95,15 +95,13 @@ func LoadConfig(path string) (*Config, error) {
95
95
dnsProviderConfigured = true
96
96
}
97
97
98
- return cfg , nil
98
+ return cfg . Validate ()
99
99
}
100
100
101
101
func defaultConfig () * Config {
102
102
return & Config {
103
- HttpListenAddr : ":8080" ,
104
- HttpsListenAddr : ":8443" ,
103
+ WebListenAddr : ":8080" ,
105
104
MetricsListenAddr : ":9091" ,
106
- ServerUrl : "https://localhost:8843" ,
107
105
Database : Database {
108
106
Type : "sqlite" ,
109
107
Url : "./ionscale.db?_pragma=busy_timeout(5000)&_pragma=journal_mode(WAL)&_pragma=foreign_keys(ON)" ,
@@ -135,17 +133,18 @@ type ServerKeys struct {
135
133
}
136
134
137
135
type Config struct {
138
- HttpListenAddr string `yaml:"http_listen_addr,omitempty" env:"HTTP_LISTEN_ADDR"`
139
- HttpsListenAddr string `yaml:"https_listen_addr,omitempty" env:"HTTPS_LISTEN_ADDR"`
136
+ WebListenAddr string `yaml:"web_listen_addr,omitempty" env:"WEB_LISTEN_ADDR"`
140
137
MetricsListenAddr string `yaml:"metrics_listen_addr,omitempty" env:"METRICS_LISTEN_ADDR"`
141
- ServerUrl string `yaml:"server_url ,omitempty" env:"SERVER_URL "`
138
+ WebPublicAddr string `yaml:"web_public_addr ,omitempty" env:"WEB_PUBLIC_ADDR "`
142
139
Tls Tls `yaml:"tls,omitempty" envPrefix:"TLS_"`
143
140
PollNet PollNet `yaml:"poll_net,omitempty" envPrefix:"POLL_NET_"`
144
141
Keys Keys `yaml:"keys,omitempty" envPrefix:"KEYS_"`
145
142
Database Database `yaml:"database,omitempty" envPrefix:"DB_"`
146
143
Auth Auth `yaml:"auth,omitempty" envPrefix:"AUTH_"`
147
144
DNS DNS `yaml:"dns,omitempty"`
148
145
Logging Logging `yaml:"logging,omitempty" envPrefix:"LOGGING_"`
146
+
147
+ WebPublicUrl * url.URL `yaml:"-"`
149
148
}
150
149
151
150
type Tls struct {
@@ -212,9 +211,24 @@ type SystemAdminPolicy struct {
212
211
Filters []string `yaml:"filters,omitempty"`
213
212
}
214
213
214
+ func (c * Config ) Validate () (* Config , error ) {
215
+ publicWebUrl , err := publicAddrToUrl (c .WebPublicAddr )
216
+ if err != nil {
217
+ return nil , err
218
+ }
219
+
220
+ c .WebPublicUrl = publicWebUrl
221
+ return c , nil
222
+ }
223
+
215
224
func (c * Config ) CreateUrl (format string , a ... interface {}) string {
216
225
path := fmt .Sprintf (format , a ... )
217
- return strings .TrimSuffix (c .ServerUrl , "/" ) + "/" + strings .TrimPrefix (path , "/" )
226
+ u := url.URL {
227
+ Scheme : c .WebPublicUrl .Scheme ,
228
+ Host : c .WebPublicUrl .Host ,
229
+ Path : path ,
230
+ }
231
+ return u .String ()
218
232
}
219
233
220
234
func (c * Config ) ReadServerKeys (defaultKeys * domain.ControlKeys ) (* ServerKeys , error ) {
0 commit comments