aboutsummaryrefslogtreecommitdiff
path: root/echo/echo_default.go
diff options
context:
space:
mode:
Diffstat (limited to 'echo/echo_default.go')
-rw-r--r--echo/echo_default.go35
1 files changed, 33 insertions, 2 deletions
diff --git a/echo/echo_default.go b/echo/echo_default.go
index 895ee6e..ddaab44 100644
--- a/echo/echo_default.go
+++ b/echo/echo_default.go
@@ -10,14 +10,27 @@ import (
10 "path" 10 "path"
11 "sync" 11 "sync"
12 12
13 gltls "code.crute.us/mcrute/golib/crypto/tls"
13 glmw "code.crute.us/mcrute/golib/echo/middleware" 14 glmw "code.crute.us/mcrute/golib/echo/middleware"
14 gltls "code.crute.us/mcrute/golib/tls" 15 "code.crute.us/mcrute/golib/echo/prometheus"
15 16
16 "github.com/labstack/echo/v4" 17 "github.com/labstack/echo/v4"
17 "github.com/labstack/echo/v4/middleware" 18 "github.com/labstack/echo/v4/middleware"
18 "github.com/labstack/gommon/log" 19 "github.com/labstack/gommon/log"
19) 20)
20 21
22// Docs: https://echo.labstack.com/guide/
23
24// TODO:
25// - Intgrate prometheus
26// - Integrate CORS
27// - Access control prometheus by IP
28// - Fix redirectors to consider port
29// - Fix redirectors to not redirect IP addresses
30// - Integrate CSRF
31// - Integrate session
32// - Use bodylimit e.Use(middleware.BodyLimit("2M"))
33
21type EchoConfig struct { 34type EchoConfig struct {
22 Debug bool 35 Debug bool
23 BindAddress string 36 BindAddress string
@@ -31,6 +44,7 @@ type EchoConfig struct {
31 CombinedHostLogFile string 44 CombinedHostLogFile string
32 RedirectToWWW bool 45 RedirectToWWW bool
33 ContentSecurityPolicy *glmw.ContentSecurityPolicyConfig 46 ContentSecurityPolicy *glmw.ContentSecurityPolicyConfig
47 PrometheusConfig *prometheus.PrometheusConfig
34} 48}
35 49
36type EchoWrapper struct { 50type EchoWrapper struct {
@@ -184,7 +198,18 @@ func NewDefaultEchoWithConfig(c EchoConfig) (*EchoWrapper, error) {
184 if c.RedirectToWWW { 198 if c.RedirectToWWW {
185 e.Use(middleware.WWWRedirect()) 199 e.Use(middleware.WWWRedirect())
186 } 200 }
187 e.Use(middleware.GzipWithConfig(middleware.GzipConfig{Level: 5})) 201 e.Use(middleware.Decompress())
202 e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
203 // TODO: This mw causes prometheus responses to show up compressed for
204 // browsers. Why?
205 Skipper: func(c echo.Context) bool {
206 if c.Path() == "/metrics" {
207 return true
208 }
209 return false
210 },
211 Level: 5,
212 }))
188 e.Use(glmw.StrictSecure()) 213 e.Use(glmw.StrictSecure())
189 214
190 if c.ContentSecurityPolicy != nil { 215 if c.ContentSecurityPolicy != nil {
@@ -193,6 +218,12 @@ func NewDefaultEchoWithConfig(c EchoConfig) (*EchoWrapper, error) {
193 return nil, fmt.Errorf("ContentSecurityPolicy is required") 218 return nil, fmt.Errorf("ContentSecurityPolicy is required")
194 } 219 }
195 220
221 if c.PrometheusConfig != nil {
222 prom := prometheus.NewPrometheusWithConfig(c.PrometheusConfig)
223 e.Use(prom.MiddlewareHandler)
224 e.GET(c.PrometheusConfig.MetricsPath, prom.MetricsHandler)
225 }
226
196 return &EchoWrapper{ 227 return &EchoWrapper{
197 Echo: e, 228 Echo: e,
198 tlsServer: ts, 229 tlsServer: ts,