-
Notifications
You must be signed in to change notification settings - Fork 34
/
leapchat.go
74 lines (60 loc) · 1.74 KB
/
leapchat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"flag"
"strings"
"github.com/cryptag/go-minilock/taber"
"github.com/cryptag/leapchat/miniware"
log "github.com/sirupsen/logrus"
)
var (
randomServerKey *taber.Keys
BUILD_DIR = "build"
)
func init() {
k, err := taber.RandomKey()
if err != nil {
log.Fatalf("Error generating random server key: %v\n", err)
}
// Setting global var
randomServerKey = k
}
func main() {
httpAddr := flag.String("http", "127.0.0.1:8080",
"Address to listen on HTTP")
httpsAddr := flag.String("https", "127.0.0.1:8443",
"Address to listen on HTTPS")
domain := flag.String("domain", "", "Domain of this service")
iframeOrigin := flag.String("iframe-origin", "",
"Origin that may embed this LeapChat instance into an iframe."+
" May include port. Only used with -prod flag.")
prod := flag.Bool("prod", false, "Run in Production mode.")
onionPush := flag.Bool("onionpush", false, "Serve OnionPush instead of LeapChat")
flag.Parse()
if *onionPush {
*httpAddr = "127.0.0.1:5001"
BUILD_DIR = "public"
}
if *prod {
log.SetLevel(log.FatalLevel)
} else {
log.SetLevel(log.DebugLevel)
}
m := miniware.NewMapper()
srv := NewServer(m, *httpAddr)
if *prod {
if *domain == "" {
log.Fatal("You must specify a -domain when using the -prod flag.")
}
manager := getAutocertManager(*domain)
// Setup http->https redirection
httpsPort := strings.SplitN(*httpsAddr, ":", 2)[1]
go redirectToHTTPS(*httpAddr, httpsPort, *domain, manager)
// Production modifications to server
ProductionServer(srv, *httpsAddr, *domain, manager, *iframeOrigin)
log.Infof("Listening on %v", *httpsAddr)
log.Fatal(srv.ListenAndServeTLS("", ""))
} else {
log.Infof("Listening on %v", *httpAddr)
log.Fatal(srv.ListenAndServe())
}
}