summaryrefslogtreecommitdiff
path: root/system/tls/enabledev.go
blob: 48a8961bd4b75422ea0e5b39699ce7390ef257ab (plain)
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
package tls

import (
	"log"
	"net/http"
	"os"
	"path/filepath"

	"github.com/bosssauce/ponzu/system/db"
)

// EnableDev generates self-signed SSL certificates to use HTTPS & HTTP/2 while
// working in a development environment. The certs are saved in a different
// directory than the production certs (from Let's Encrypt), so that the
// acme/autocert package doesn't mistake them for it's own.
// Additionally, a TLS server is started using the default http mux.
func EnableDev() {
	setupDev()

	pwd, err := os.Getwd()
	if err != nil {
		log.Fatalln("Couldn't find working directory to activate dev certificates:", err)
	}

	vendorPath := filepath.Join(pwd, "cmd", "ponzu", "vendor", "github.com", "ponzu-cms", "ponzu", "system", "tls")

	cert := filepath.Join(vendorPath, "devcerts", "cert.pem")
	key := filepath.Join(vendorPath, "devcerts", "key.pem")

	port := db.ConfigCache("https_port")
	log.Fatalln(http.ListenAndServeTLS(":"+port, cert, key, nil))
}