Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Add HTTP/TLS support
Browse files Browse the repository at this point in the history
  • Loading branch information
farshidtz committed Mar 26, 2021
1 parent 8aa7265 commit edd7e06
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
7 changes: 7 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ type HTTPConfig struct {
PublicEndpoint string `json:"publicEndpoint"`
BindAddr string `json:"bindAddr"`
BindPort int `json:"bindPort"`
TLSConfig *TLSConfig `json:"tls"`
Auth validator.Conf `json:"auth"`
}

type TLSConfig struct {
Enabled bool `json:"enabled"`
KeyFile string `json:"keyFile"`
CertFile string `json:"certFile"`
}

type ServiceCatalog struct {
Enabled bool `json:"enabled"`
Discover bool `json:"discover"`
Expand Down
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,16 @@ func main() {
if err != nil {
panic(err)
}
log.Printf("HTTP server listening on %v", addr)
go func() { log.Fatalln(http.Serve(listener, nRouter)) }()

go func() {
if config.HTTP.TLSConfig.Enabled {
log.Printf("HTTP/TLS server listening on %v", addr)
log.Fatalf("Error starting HTTP/TLS Server: %s", http.ServeTLS(listener, nRouter, config.HTTP.TLSConfig.CertFile, config.HTTP.TLSConfig.KeyFile))
} else {
log.Printf("HTTP server listening on %v", addr)
log.Fatalf("Error starting HTTP Server: %s", http.Serve(listener, nRouter))
}
}()

// Publish service using DNS-SD
if config.DNSSD.Publish.Enabled {
Expand Down
7 changes: 6 additions & 1 deletion sample_conf/thing-directory.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
"publicEndpoint": "http://fqdn-of-the-host:8081",
"bindAddr": "0.0.0.0",
"bindPort": 8081,
"auth": {
"tls": {
"enabled": false,
"keyFile": "./tls/key.pem",
"certFile": "./tls/cert.pem"
},
"auth": {
"enabled": true,
"provider": "keycloak",
"providerURL": "https://provider-url",
"clientID": "sampleTD",
Expand Down

0 comments on commit edd7e06

Please sign in to comment.