Skip to content

Commit

Permalink
Add static folder to explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
meyer9 committed May 17, 2019
1 parent 38fe201 commit 7062996
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions explorer/assets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body {}
27 changes: 25 additions & 2 deletions explorer/explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/binary"
"io"
"os"
"os/signal"
"syscall"
"text/template"
"time"

Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions explorer/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>Block Explorer</title>
<link rel="stylesheet" type="text/css" href="/static/style.css" />
<style>
body {
margin: 0;
Expand Down

0 comments on commit 7062996

Please sign in to comment.