summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-02-11 17:13:53 +0100
committerkali kaneko (leap communications) <kali@leap.se>2020-02-11 19:05:29 +0100
commit828ee14b4e903bbda9291bc9ee09ff98b66003c7 (patch)
tree171d4ba1766274087f2d29f233e90e59f5781225 /main.go
parentecaa22111ee8e34111080139e1e8a92b90e30158 (diff)
[feat] metrics listen in separate port
Diffstat (limited to 'main.go')
-rw-r--r--main.go36
1 files changed, 22 insertions, 14 deletions
diff --git a/main.go b/main.go
index ac85c90..fe2fcde 100644
--- a/main.go
+++ b/main.go
@@ -16,34 +16,42 @@ func main() {
ch := web.NewCertHandler(opts.CaCrt, opts.CaKey)
authenticator := auth.GetAuthenticator(opts, false)
+ srv := http.NewServeMux()
+
/* protected routes */
/* TODO https://0xacab.org/leap/vpnweb/issues/4
http.HandleFunc("/3/refresh-token", auth.RefreshAuthMiddleware(opts.Auth))
*/
-
- http.HandleFunc("/3/auth", web.AuthMiddleware(authenticator.CheckCredentials, opts))
- http.Handle("/3/cert", web.RestrictedMiddleware(authenticator.NeedsCredentials, ch.CertResponder, opts))
+ srv.HandleFunc("/3/auth", web.AuthMiddleware(authenticator.CheckCredentials, opts))
+ srv.Handle("/3/cert", web.RestrictedMiddleware(authenticator.NeedsCredentials, ch.CertResponder, opts))
/* static files */
- web.HttpFileHandler("/3/configs.json", opts.ApiPath+"/3/configs.json")
- web.HttpFileHandler("/3/service.json", opts.ApiPath+"/3/service.json")
- web.HttpFileHandler("/3/config/eip-service.json", opts.ApiPath+"/3/eip-service.json")
- web.HttpFileHandler("/provider.json", opts.ApiPath+"provider.json")
- web.HttpFileHandler("/ca.crt", opts.ProviderCaPath)
- web.HttpFileHandler("/3/ca.crt", opts.ProviderCaPath)
+ web.HttpFileHandler(srv, "/3/configs.json", opts.ApiPath+"/3/configs.json")
+ web.HttpFileHandler(srv, "/3/service.json", opts.ApiPath+"/3/service.json")
+ web.HttpFileHandler(srv, "/3/config/eip-service.json", opts.ApiPath+"/3/eip-service.json")
+ web.HttpFileHandler(srv, "/provider.json", opts.ApiPath+"provider.json")
+ web.HttpFileHandler(srv, "/ca.crt", opts.ProviderCaPath)
+ web.HttpFileHandler(srv, "/3/ca.crt", opts.ProviderCaPath)
+
+ mtr := http.NewServeMux()
+ mtr.Handle("/metrics", promhttp.Handler())
/* prometheus metrics */
- http.Handle("/metrics", promhttp.Handler())
+ go func() {
+ pstr := ":" + opts.MetricsPort
+ log.Println("/metrics endpoint in port", opts.MetricsPort)
+ log.Fatal(http.ListenAndServe(pstr, mtr))
+ }()
+ /* api server */
pstr := ":" + opts.Port
- log.Println("Listening in port", opts.Port)
-
+ log.Println("API listening in port", opts.Port)
if opts.Tls == true {
- log.Fatal(http.ListenAndServeTLS(pstr, opts.TlsCrt, opts.TlsKey, nil))
+ log.Fatal(http.ListenAndServeTLS(pstr, opts.TlsCrt, opts.TlsKey, srv))
} else {
- log.Fatal(http.ListenAndServe(pstr, nil))
+ log.Fatal(http.ListenAndServe(pstr, srv))
}
}