Skip to content

Commit 59c4047

Browse files
brian-dohertysentriz
andcommittedMar 14, 2022
feat(server): support TLS
* Added https support. Will revert to http if either cert or key are empty strings. * Update server/server.go Co-authored-by: Senan Kelly <senan@senan.xyz> * Fixed lint issues. Co-authored-by: Senan Kelly <senan@senan.xyz>
1 parent 5155dee commit 59c4047

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed
 

‎README.md

+13-11
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,19 @@ view the admin UI at http://localhost:4747
149149

150150
## configuration options
151151

152-
|env var|command line arg|description|
153-
|---|---|---|
154-
|`GONIC_MUSIC_PATH`|`-music-path`|path to your music collection (see also multi-folder support below)|
155-
|`GONIC_PODCAST_PATH`|`-podcast-path`|path to a podcasts directory|
156-
|`GONIC_CACHE_PATH`|`-cache-path`|path to store audio transcodes, covers, etc|
157-
|`GONIC_DB_PATH`|`-db-path`|**optional** path to database file|
158-
|`GONIC_LISTEN_ADDR`|`-listen-addr`|**optional** host and port to listen on (eg. `0.0.0.0:4747`, `127.0.0.1:4747`) (*default* `0.0.0.0:4747`)|
159-
|`GONIC_PROXY_PREFIX`|`-proxy-prefix`|**optional** url path prefix to use if behind reverse proxy. eg `/gonic` (see example configs below)|
160-
|`GONIC_SCAN_INTERVAL`|`-scan-interval`|**optional** interval (in minutes) to check for new music (automatic scanning disabled if omitted)|
161-
|`GONIC_JUKEBOX_ENABLED`|`-jukebox-enabled`|**optional** whether the subsonic [jukebox api](https://airsonic.github.io/docs/jukebox/) should be enabled|
162-
|`GONIC_GENRE_SPLIT`|`-genre-split`|**optional** a string or character to split genre tags on for multi-genre support (eg. `;`)|
152+
| env var | command line arg | description |
153+
| ----------------------- | ------------------ | ----------------------------------------------------------------------------------------------------------- |
154+
| `GONIC_MUSIC_PATH` | `-music-path` | path to your music collection (see also multi-folder support below) |
155+
| `GONIC_PODCAST_PATH` | `-podcast-path` | path to a podcasts directory |
156+
| `GONIC_CACHE_PATH` | `-cache-path` | path to store audio transcodes, covers, etc |
157+
| `GONIC_DB_PATH` | `-db-path` | **optional** path to database file |
158+
| `GONIC_LISTEN_ADDR` | `-listen-addr` | **optional** host and port to listen on (eg. `0.0.0.0:4747`, `127.0.0.1:4747`) (_default_ `0.0.0.0:4747`) |
159+
| `GONIC_TLS_CERT` | `-tls-cert` | **optional** path to a TLS cert (enables HTTPS listening) |
160+
| `GONIC_TLS_KEY` | `-tls-key` | **optional** path to a TLS key (enables HTTPS listening) |
161+
| `GONIC_PROXY_PREFIX` | `-proxy-prefix` | **optional** url path prefix to use if behind reverse proxy. eg `/gonic` (see example configs below) |
162+
| `GONIC_SCAN_INTERVAL` | `-scan-interval` | **optional** interval (in minutes) to check for new music (automatic scanning disabled if omitted) |
163+
| `GONIC_JUKEBOX_ENABLED` | `-jukebox-enabled` | **optional** whether the subsonic [jukebox api](https://airsonic.github.io/docs/jukebox/) should be enabled |
164+
| `GONIC_GENRE_SPLIT` | `-genre-split` | **optional** a string or character to split genre tags on for multi-genre support (eg. `;`) |
163165

164166
## screenshots
165167

‎cmd/gonic/gonic.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const (
3030
func main() {
3131
set := flag.NewFlagSet(gonic.Name, flag.ExitOnError)
3232
confListenAddr := set.String("listen-addr", "0.0.0.0:4747", "listen address (optional)")
33+
confTLSCert := set.String("tls-cert", "", "path to TLS certificate (optional)")
34+
confTLSKey := set.String("tls-key", "", "path to TLS private key (optional)")
3335
confPodcastPath := set.String("podcast-path", "", "path to podcasts")
3436
confCachePath := set.String("cache-path", "", "path to cache")
3537
confDBPath := set.String("db-path", "gonic.db", "path to database (optional)")
@@ -125,7 +127,7 @@ func main() {
125127
}
126128

127129
var g run.Group
128-
g.Add(server.StartHTTP(*confListenAddr))
130+
g.Add(server.StartHTTP(*confListenAddr, *confTLSCert, *confTLSKey))
129131
g.Add(server.StartSessionClean(cleanTimeDuration))
130132
g.Add(server.StartPodcastRefresher(time.Hour))
131133
if *confScanInterval > 0 {

‎server/server.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ type (
264264
FuncInterrupt func(error)
265265
)
266266

267-
func (s *Server) StartHTTP(listenAddr string) (FuncExecute, FuncInterrupt) {
267+
func (s *Server) StartHTTP(listenAddr string, tlsCert string, tlsKey string) (FuncExecute, FuncInterrupt) {
268268
list := &http.Server{
269269
Addr: listenAddr,
270270
Handler: s.router,
@@ -274,6 +274,9 @@ func (s *Server) StartHTTP(listenAddr string) (FuncExecute, FuncInterrupt) {
274274
}
275275
return func() error {
276276
log.Print("starting job 'http'\n")
277+
if tlsCert != "" && tlsKey != "" {
278+
return list.ListenAndServeTLS(tlsCert, tlsKey)
279+
}
277280
return list.ListenAndServe()
278281
}, func(_ error) {
279282
// stop job

0 commit comments

Comments
 (0)
Please sign in to comment.