Skip to content

Commit

Permalink
Serve custom assets from current directory under /custom
Browse files Browse the repository at this point in the history
  • Loading branch information
zh32 committed Jun 9, 2018
1 parent 226426b commit 866e3d7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,22 @@ Run DRTelemetry from a terminal and add the following parameters.
drtelemetry.exe --http 0.0.0.0:8080
``

### Change styling
### Customize styling

You can change the styling by altering the CSS. This can be done with browser extensions like [Stylish](https://chrome.google.com/webstore/detail/stylish-custom-themes-for/fjnbnpbmkenffdnngjfgmeleoegfcffe).
You can replace the stylesheet with your own.
Just add a css file to the directory from where you start DRTelemetry and add a parameter to the browser URL.
```css
$ custom.css

p {
color: violet;
}
```

Browser-URL
``http://localhost:8080/?style=custom.css``

**Note:** DRTelemetry will serve all files in its current directory under the path ``/custom/<filename>``.

## Contributing

Expand Down
15 changes: 12 additions & 3 deletions ui/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ var upgrader = websocket.Upgrader{} // use default options

var connections []*websocket.Conn

var box = packr.NewBox("../template")
var box = packr.NewBox("../resources")
var ui = box.String("ui.html")
var homeTemplate = template.Must(template.New("").Parse(ui))

func ListenAndServe(dataChannel chan telemetry.TelemetryData) {
http.HandleFunc("/ws", HandleWs)
http.Handle("/assets/", http.FileServer(box))
http.Handle("/custom/", http.StripPrefix("/custom/", http.FileServer(http.Dir("."))))
http.HandleFunc("/", HandleUi)

go func() {
Expand All @@ -49,6 +51,13 @@ func HandleWs(w http.ResponseWriter, r *http.Request) {
select {}
}

type TemplateData struct {
CustomStyle string
WebsocketHost string
}

func HandleUi(w http.ResponseWriter, r *http.Request) {
homeTemplate.Execute(w, "ws://"+r.Host+"/ws")
}
templateData := TemplateData{r.URL.Query().Get("style"), "ws://" + r.Host + "/ws"}

homeTemplate.Execute(w, templateData)
}

0 comments on commit 866e3d7

Please sign in to comment.