Network: allow configuring external url (BC) (#25285)
This commit is contained in:
parent
bb61acc99c
commit
b535d2ed07
14 changed files with 195 additions and 126 deletions
|
|
@ -1,7 +1,7 @@
|
|||
# open evcc at http://evcc.local:7070
|
||||
network:
|
||||
schema: http
|
||||
host: evcc.local # .local suffix announces the hostname on MDNS
|
||||
host: evcc # announces the hostname on mDNS
|
||||
port: 7070
|
||||
|
||||
log: debug
|
||||
|
|
|
|||
|
|
@ -261,13 +261,13 @@ func runRoot(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
|
||||
// announce on mDNS
|
||||
if err == nil && strings.HasSuffix(conf.Network.Host, ".local") {
|
||||
if err == nil {
|
||||
err = configureMDNS(conf.Network)
|
||||
}
|
||||
|
||||
// start SHM server
|
||||
if err == nil {
|
||||
err = wrapErrorWithClass(ClassSHM, configureSHM(&conf.SHM, site, httpd))
|
||||
err = wrapErrorWithClass(ClassSHM, configureSHM(&conf.SHM, conf.Network.ExternalURL(), site, httpd))
|
||||
}
|
||||
|
||||
// start HEMS server
|
||||
|
|
|
|||
21
cmd/setup.go
21
cmd/setup.go
|
|
@ -63,9 +63,8 @@ var conf = globalconfig.All{
|
|||
Interval: 10 * time.Second,
|
||||
Log: "info",
|
||||
Network: globalconfig.Network{
|
||||
Schema: "http",
|
||||
Host: "evcc.local",
|
||||
Port: 7070,
|
||||
Host: "",
|
||||
Port: 7070,
|
||||
},
|
||||
Mqtt: globalconfig.Mqtt{
|
||||
Topic: "evcc",
|
||||
|
|
@ -676,14 +675,14 @@ func configureMqtt(conf *globalconfig.Mqtt) error {
|
|||
}
|
||||
|
||||
// setup SHM
|
||||
func configureSHM(conf *shm.Config, site *core.Site, httpd *server.HTTPd) error {
|
||||
func configureSHM(conf *shm.Config, externalUrl string, site *core.Site, httpd *server.HTTPd) error {
|
||||
if settings.Exists(keys.Shm) {
|
||||
if err := settings.Json(keys.Shm, &conf); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := shm.NewFromConfig(*conf, site, httpd.Addr, httpd.Router()); err != nil {
|
||||
if err := shm.NewFromConfig(*conf, externalUrl, site, httpd.Addr, httpd.Router()); err != nil {
|
||||
return fmt.Errorf("failed configuring shm: %w", err)
|
||||
}
|
||||
|
||||
|
|
@ -751,8 +750,18 @@ func networkSettings(conf *globalconfig.Network) error {
|
|||
// setup MDNS
|
||||
func configureMDNS(conf globalconfig.Network) error {
|
||||
host := strings.TrimSuffix(conf.Host, ".local")
|
||||
if host == "" {
|
||||
host = "evcc"
|
||||
}
|
||||
|
||||
zc, err := zeroconf.RegisterProxy("evcc", "_http._tcp", "local.", conf.Port, host, nil, []string{"path=/"}, nil)
|
||||
internalURL := conf.InternalURL()
|
||||
text := []string{"path=/", "internal_url=" + internalURL}
|
||||
|
||||
if externalURL := conf.ExternalURL(); externalURL != internalURL {
|
||||
text = append(text, "external_url="+externalURL)
|
||||
}
|
||||
|
||||
zc, err := zeroconf.RegisterProxy("evcc", "_http._tcp", "local.", conf.Port, host, nil, text, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("mDNS announcement: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ func tronityToken(conf globalconfig.All, vehicleConf config.Named) (*oauth2.Toke
|
|||
}
|
||||
|
||||
if oc.RedirectURL = cc.RedirectURI; oc.RedirectURL == "" {
|
||||
oc.RedirectURL = fmt.Sprintf("%s/auth/tronity", conf.Network.URI())
|
||||
oc.RedirectURL = fmt.Sprintf("%s/auth/tronity", conf.Network.ExternalURL())
|
||||
}
|
||||
|
||||
return tronityAuthorize(conf.Network.HostPort(), oc)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue