-
Notifications
You must be signed in to change notification settings - Fork 15
/
pursuance.go
70 lines (55 loc) · 1.52 KB
/
pursuance.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
package main
import (
"flag"
"strings"
"github.com/cryptag/minishare/miniware"
log "github.com/Sirupsen/logrus"
"github.com/cathalgarvey/go-minilock/taber"
)
var (
randomServerKey *taber.Keys
THIS_DOMAIN_BASE_URL string
)
func init() {
k, err := taber.RandomKey()
if err != nil {
log.Fatalf("Error generating random server key: %v", err)
}
// Setting global var
randomServerKey = k
}
func main() {
httpAddr := flag.String("http", "127.0.0.1:8082",
"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")
prod := flag.Bool("prod", false, "Run in Production mode.")
flag.Parse()
if *prod {
log.SetLevel(log.FatalLevel)
} else {
log.SetLevel(log.DebugLevel)
}
m := miniware.NewMapper()
srv := NewServer(m, *httpAddr)
go NewEmailer()
if *prod {
if *domain == "" {
log.Fatal("You must specify a -domain when using the -prod flag.")
}
THIS_DOMAIN_BASE_URL = "https://" + *domain
manager := getAutocertManager(*domain)
// Setup http->https redirection
httpsPort := strings.SplitN(*httpsAddr, ":", 2)[1]
go redirectToHTTPS(*httpAddr, httpsPort, manager)
// Production modifications to server
ProductionServer(srv, *httpsAddr, *domain, manager)
log.Infof("Listening on %v", *httpsAddr)
log.Fatal(srv.ListenAndServeTLS("", ""))
} else {
THIS_DOMAIN_BASE_URL = "http://" + *httpAddr
log.Infof("Listening on %v", *httpAddr)
log.Fatal(srv.ListenAndServe())
}
}