From 70629965b2a38350293b16cb588e597332439cf9 Mon Sep 17 00:00:00 2001 From: Julian Meyer Date: Fri, 17 May 2019 11:29:32 -0700 Subject: [PATCH] Add static folder to explorer --- explorer/assets/style.css | 1 + explorer/explorer.go | 27 +++++++++++++++++++++++++-- explorer/templates/index.html | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 explorer/assets/style.css diff --git a/explorer/assets/style.css b/explorer/assets/style.css new file mode 100644 index 00000000..208d16d4 --- /dev/null +++ b/explorer/assets/style.css @@ -0,0 +1 @@ +body {} diff --git a/explorer/explorer.go b/explorer/explorer.go index 20655d4a..24e4edd5 100644 --- a/explorer/explorer.go +++ b/explorer/explorer.go @@ -5,6 +5,8 @@ import ( "encoding/binary" "io" "os" + "os/signal" + "syscall" "text/template" "time" @@ -341,6 +343,19 @@ func (ex *Explorer) postProcessHook(block *primitives.Block, state *primitives.S } } +func (ex *Explorer) exit() { + err := ex.chainDB.Close() + if err != nil { + panic(err) + } + + for _, p := range ex.hostNode.GetPeerList() { + p.Disconnect() + } + + os.Exit(0) +} + // StartExplorer starts the block explorer func (ex *Explorer) StartExplorer() error { err := ex.loadDatabase() @@ -353,6 +368,15 @@ func (ex *Explorer) StartExplorer() error { return err } + signalHandler := make(chan os.Signal, 1) + signal.Notify(signalHandler, os.Interrupt, syscall.SIGTERM) + + go func() { + <-signalHandler + + ex.exit() + }() + err = ex.loadBlockchain() if err != nil { return err @@ -377,12 +401,11 @@ func (ex *Explorer) StartExplorer() error { e := echo.New() e.Renderer = t + e.Static("/static", "assets") e.GET("/", ex.renderIndex) e.GET("/b/:blockHash", ex.renderBlock) e.GET("/v/:validatorHash", ex.renderValidator) - defer ex.chainDB.Close() - e.Logger.Fatal(e.Start(":1323")) return nil diff --git a/explorer/templates/index.html b/explorer/templates/index.html index 9da98640..2613269d 100644 --- a/explorer/templates/index.html +++ b/explorer/templates/index.html @@ -2,6 +2,7 @@ Block Explorer +