Skip to content

Commit

Permalink
Merge pull request #60 from SpectoLabs/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Karolis Rusenas committed Jan 8, 2016
2 parents 395e45d + 419268e commit c6d5aff
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ links.p

.vagrant/

static/js/node_modules
static/node_modules
static/dist
14 changes: 13 additions & 1 deletion admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"io/ioutil"
"net/http"

// static assets
_ "github.com/SpectoLabs/hoverfly/statik"
"github.com/rakyll/statik/fs"

log "github.com/Sirupsen/logrus"
"github.com/codegangsta/negroni"
"github.com/go-zoo/bone"
Expand Down Expand Up @@ -49,6 +53,14 @@ func (d *DBClient) startAdminInterface() {
func getBoneRouter(d DBClient) *bone.Mux {
mux := bone.New()

// preparing static assets for embedded admin
statikFS, err := fs.New()
if err != nil {
log.WithFields(log.Fields{
"Error": err.Error(),
}).Error("Failed to load statikFS, admin UI might not work :(")
}

mux.Get("/records", http.HandlerFunc(d.AllRecordsHandler))
mux.Delete("/records", http.HandlerFunc(d.DeleteAllRecordsHandler))
mux.Post("/records", http.HandlerFunc(d.ImportRecordsHandler))
Expand All @@ -58,7 +70,7 @@ func getBoneRouter(d DBClient) *bone.Mux {
mux.Get("/state", http.HandlerFunc(d.CurrentStateHandler))
mux.Post("/state", http.HandlerFunc(d.stateHandler))

mux.Handle("/*", http.FileServer(http.Dir("static")))
mux.Handle("/*", http.FileServer(statikFS))

return mux
}
Expand Down
1 change: 1 addition & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ import:
- package: github.com/codegangsta/negroni
- package: github.com/go-zoo/bone
- package: github.com/boltdb/bolt
- package: github.com/rakyll/statik
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ <h4>Hoverfly</h4>

<!-- End Document
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<script src="js/dist/home-bundle.js"></script>
<script src="js/home-bundle.js"></script>
</body>
</html>
20 changes: 0 additions & 20 deletions static/js/dist/home-bundle.js

This file was deleted.

1 change: 1 addition & 0 deletions static/js/package.json → static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"babel-plugin-transform-runtime": "^6.3.13",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"copy-webpack-plugin": "^0.3.3",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"superagent": "^1.5.0",
Expand Down
29 changes: 29 additions & 0 deletions static/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Hoverfly admin UI

These files serve admin interface. Since Hoverfly is API first - admin interface is supposed to be minimalistic since
all of the actions such as mode change, record wiping, import/export actions should be automated and done through the API.

## Building admin interface

Admin interface is created using ReactJS. To build it - use webpack.

webpack

During development, useful command to build upon any change:

webpack --watch

To build minimized version for production, add "-p" flag:

webpack -p

Hoverfly uses [statik](https://github.com/rakyll/statik) to embed whole UI into the binary:

go get github.com/rakyll/statik
$GOPATH/bin/statik -src=./static/dist


Then _/statik/statik.go_ should then be updated. Rebuild Hoverfly so it is then included into binary.
Commit it in order to see changes.


12 changes: 10 additions & 2 deletions static/js/webpack.config.js → static/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
var path = require("path");
var webpack = require('webpack');
var CopyWebpackPlugin = require('copy-webpack-plugin');


module.exports = {
context: __dirname,
entry: {
home: "./src/home.jsx"
home: "./js/src/home.jsx"
},
output: {
path: path.resolve("./dist"),
filename: "[name]-bundle.js"
filename: "js/[name]-bundle.js"
},
plugins: [
new CopyWebpackPlugin([
{ from: 'index.html' },
{ from: 'css', to: 'css' },
{ from: 'images', to: 'images' }
])
],

module: {
loaders: [
Expand Down
10 changes: 10 additions & 0 deletions statik/statik.go

Large diffs are not rendered by default.

0 comments on commit c6d5aff

Please sign in to comment.