@@ -16,8 +16,13 @@ import (
1616 "github.com/go-chi/cors"
1717 "github.com/spf13/viper"
1818 _ "modernc.org/sqlite"
19+
20+ _ "embed"
1921)
2022
23+ //go:embed favicon.ico
24+ var faviconData []byte
25+
2126var version = "development"
2227
2328type Config struct {
@@ -28,6 +33,7 @@ type Config struct {
2833 TrustedProxies []string `mapstructure:"trusted_proxies"`
2934 CORSAllowedOrigins []string `mapstructure:"cors_allowed_origins"`
3035 DashboardEnabled bool `mapstructure:"dashboard_enabled"`
36+ BadgeEnabled bool `mapstructure:"badge_enabled"`
3137}
3238
3339func main () {
@@ -40,6 +46,7 @@ func main() {
4046 v .SetDefault ("trusted_proxies" , []string {"" })
4147 v .SetDefault ("cors_allowed_origins" , []string {"*" })
4248 v .SetDefault ("dashboard_enabled" , true )
49+ v .SetDefault ("badge_enabled" , true )
4350
4451 v .AutomaticEnv ()
4552
@@ -84,7 +91,6 @@ func main() {
8491
8592 instancesHandler := NewInstancesHandler (queries )
8693 healthHandler := NewHealthHandler ()
87- dashboardHandler := NewDashboardHandler (queries )
8894
8995 router .Get ("/v1/healthz" , healthHandler .Health )
9096
@@ -100,12 +106,27 @@ func main() {
100106 r .Post ("/v1/instances/heartbeat" , instancesHandler .Heartbeat )
101107 })
102108
109+ router .Get ("/robots.txt" , func (w http.ResponseWriter , r * http.Request ) {
110+ w .Header ().Set ("Content-Type" , "text/plain" )
111+ w .WriteHeader (http .StatusOK )
112+ w .Write ([]byte ("User-agent: *\n Disallow: /" ))
113+ })
114+
103115 if config .DashboardEnabled {
116+ dashboardHandler := NewDashboardHandler (queries )
104117 router .Get ("/dashboard" , dashboardHandler .Dashboard )
118+ router .Get ("/favicon.ico" , func (w http.ResponseWriter , r * http.Request ) {
119+ w .Header ().Set ("Content-Type" , "image/x-icon" )
120+ w .WriteHeader (http .StatusOK )
121+ w .Write (faviconData )
122+ })
123+
105124 }
106125
107- router .Get ("/favicon.ico" , dashboardHandler .Favicon )
108- router .Get ("/robots.txt" , dashboardHandler .Robots )
126+ if config .BadgeEnabled {
127+ badgeHandler := NewBadgeHandler (queries )
128+ router .Get ("/v1/badge" , badgeHandler .Badge )
129+ }
109130
110131 srv := & http.Server {
111132 Addr : fmt .Sprintf ("%s:%d" , config .Address , config .Port ),
0 commit comments