Skip to content
This repository was archived by the owner on Sep 4, 2018. It is now read-only.

Adding SSL support to eventsource #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
nurl "net/url"
"os"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -174,16 +175,35 @@ func NewHub() *Hub {

func main() {
sseString := os.Getenv("SSE_HOST")
sslKey := os.Getenv("SSL_KEY")
sslCert := os.Getenv("SSL_CERT")
if sseString == "" {
log.Fatal("SSE_HOST is not set, example: SSE_HOST=localhost:3000")
log.Fatal("SSE_HOST is not set, example: SSE_HOST=localhost:3000 for non SSL or SSE_HOST=localhost:3001 for SSL. Please set SSL_KEY and SSL_CERT to full path of priv key and cert")
}
log.Println("[Info] botbot-eventsource is listening on " + sseString)
if ok, _ := regexp.Match("3000", []byte(sseString)); ok {

log.Println("[Info] Starting the eventsource Hub")
h := NewHub()
log.Println("[Info] botbot-eventsource is listening on " + sseString)

// eventsource endpoints
http.HandleFunc(ssePath, h.EventSourceHandler)
log.Println("[Info] Starting the eventsource Hub")
h := NewHub()

log.Fatalln(http.ListenAndServe(sseString, nil))
// eventsource endpoints
http.HandleFunc(ssePath, h.EventSourceHandler)

log.Fatalln(http.ListenAndServe(sseString, nil))

} else if sslKey == "" {
log.Fatal("SSL_KEY is not set, set it to full path to key file")
} else if sslCert == "" {
log.Fatal("SSL_CERT is not set, set it to full path to cert file")
} else {
log.Println("[Info] botbot-eventsource is listening on " + sseString)

log.Println("[Info] Starting the eventsource Hub")
h := NewHub()

// eventsource endpoints
http.HandleFunc(ssePath, h.EventSourceHandler)
log.Fatalln(http.ListenAndServeTLS(sseString, sslCert, sslKey, nil))
}
}