@@ -62,7 +62,7 @@ func newMetEngine(reg *prometheus.Registry, eng ds.EngineI, _cfg *config.Config)
6262 Help : "Start time, in unixtime (seconds)" ,
6363 }, func () float64 { return startUnix }),
6464 )
65- mux .Handle ("/metrics" , promhttp .HandlerFor (reg , promhttp.HandlerOpts {}))
65+ mux .Handle ("/metrics" , corsHandler ( promhttp .HandlerFor (reg , promhttp.HandlerOpts {}) ))
6666
6767 mux .HandleFunc ("/health" , func (hw http.ResponseWriter , hr * http.Request ) {
6868 block , _ := eng .LastSyncedBlock ()
@@ -77,3 +77,14 @@ func newMetEngine(reg *prometheus.Registry, eng ds.EngineI, _cfg *config.Config)
7777
7878 utils .ServerFromMux (mux , _cfg .Port )
7979}
80+
81+ func corsHandler (h http.Handler ) http.HandlerFunc {
82+ return func (w http.ResponseWriter , r * http.Request ) {
83+ w .Header ().Add ("Connection" , "keep-alive" )
84+ w .Header ().Add ("Access-Control-Allow-Origin" , "*" )
85+ w .Header ().Add ("Access-Control-Allow-Methods" , "OPTIONS, GET" )
86+ w .Header ().Add ("Access-Control-Allow-Headers" , "content-type" )
87+ w .Header ().Add ("Access-Control-Max-Age" , "86400" )
88+ h .ServeHTTP (w , r )
89+ }
90+ }
0 commit comments