diff options
author | Kali Kaneko <kali@leap.se (leap communications)> | 2019-07-02 20:04:39 +0200 |
---|---|---|
committer | Kali Kaneko <kali@leap.se (leap communications)> | 2019-07-02 20:04:39 +0200 |
commit | 159b4322aeb0d4decb584a2f55182b67c17bf6d0 (patch) | |
tree | ab82a0792ae8247556a31d6af861493ba0f7b6f3 | |
parent | 05ac08d1b0f87de02d5d6c3144673994f2e2cb4b (diff) |
file handler
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | main.go | 12 |
2 files changed, 14 insertions, 0 deletions
@@ -4,5 +4,7 @@ demo: ./vpnweb -caCrt test/files/ca.crt -caKey test/files/ca.key clean: rm -f public/1/* + rm public/ca.crt populate: cp test/1/* public/1/ + cp test/files/ca.crt public/ @@ -9,6 +9,7 @@ import ( "strconv" ) +// TODO get this from the config yaml? const keySize = 2048 const expiryDays = 28 @@ -34,6 +35,12 @@ func doFilesSanityCheck(caCrt string, caKey string) { } } +func httpFileHandler(route string, path string) { + http.HandleFunc(route, func(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, path) + }) +} + func main() { var caCrt = flag.String("caCrt", "", "path to the CA public key") var caKey = flag.String("caKey", "", "path to the CA private key") @@ -53,6 +60,11 @@ func main() { ci := newCaInfo(*caCrt, *caKey) ch := certHandler{ci} + // add routes here http.HandleFunc("/1/cert", ch.certResponder) + httpFileHandler("/1/ca.crt", "./public/ca.crt") + httpFileHandler("/1/configs.json", "./public/1/configs.json") + httpFileHandler("/1/service.json", "./public/1/service.json") + log.Fatal(http.ListenAndServe(":"+strconv.Itoa(*port), nil)) } |