Skip to content

Commit c6d5aff

Browse files
author
Karolis Rusenas
committed
Merge pull request #60 from SpectoLabs/develop
Develop
2 parents 395e45d + 419268e commit c6d5aff

File tree

9 files changed

+67
-25
lines changed

9 files changed

+67
-25
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ links.p
3333

3434
.vagrant/
3535

36-
static/js/node_modules
36+
static/node_modules
37+
static/dist

admin.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import (
66
"io/ioutil"
77
"net/http"
88

9+
// static assets
10+
_ "github.com/SpectoLabs/hoverfly/statik"
11+
"github.com/rakyll/statik/fs"
12+
913
log "github.com/Sirupsen/logrus"
1014
"github.com/codegangsta/negroni"
1115
"github.com/go-zoo/bone"
@@ -49,6 +53,14 @@ func (d *DBClient) startAdminInterface() {
4953
func getBoneRouter(d DBClient) *bone.Mux {
5054
mux := bone.New()
5155

56+
// preparing static assets for embedded admin
57+
statikFS, err := fs.New()
58+
if err != nil {
59+
log.WithFields(log.Fields{
60+
"Error": err.Error(),
61+
}).Error("Failed to load statikFS, admin UI might not work :(")
62+
}
63+
5264
mux.Get("/records", http.HandlerFunc(d.AllRecordsHandler))
5365
mux.Delete("/records", http.HandlerFunc(d.DeleteAllRecordsHandler))
5466
mux.Post("/records", http.HandlerFunc(d.ImportRecordsHandler))
@@ -58,7 +70,7 @@ func getBoneRouter(d DBClient) *bone.Mux {
5870
mux.Get("/state", http.HandlerFunc(d.CurrentStateHandler))
5971
mux.Post("/state", http.HandlerFunc(d.stateHandler))
6072

61-
mux.Handle("/*", http.FileServer(http.Dir("static")))
73+
mux.Handle("/*", http.FileServer(statikFS))
6274

6375
return mux
6476
}

glide.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ import:
66
- package: github.com/codegangsta/negroni
77
- package: github.com/go-zoo/bone
88
- package: github.com/boltdb/bolt
9+
- package: github.com/rakyll/statik

static/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ <h4>Hoverfly</h4>
4747

4848
<!-- End Document
4949
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
50-
<script src="js/dist/home-bundle.js"></script>
50+
<script src="js/home-bundle.js"></script>
5151
</body>
5252
</html>

static/js/dist/home-bundle.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

static/js/package.json renamed to static/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"babel-plugin-transform-runtime": "^6.3.13",
2929
"babel-preset-es2015": "^6.3.13",
3030
"babel-preset-react": "^6.3.13",
31+
"copy-webpack-plugin": "^0.3.3",
3132
"react": "^0.14.3",
3233
"react-dom": "^0.14.3",
3334
"superagent": "^1.5.0",

static/readme.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Hoverfly admin UI
2+
3+
These files serve admin interface. Since Hoverfly is API first - admin interface is supposed to be minimalistic since
4+
all of the actions such as mode change, record wiping, import/export actions should be automated and done through the API.
5+
6+
## Building admin interface
7+
8+
Admin interface is created using ReactJS. To build it - use webpack.
9+
10+
webpack
11+
12+
During development, useful command to build upon any change:
13+
14+
webpack --watch
15+
16+
To build minimized version for production, add "-p" flag:
17+
18+
webpack -p
19+
20+
Hoverfly uses [statik](https://github.com/rakyll/statik) to embed whole UI into the binary:
21+
22+
go get github.com/rakyll/statik
23+
$GOPATH/bin/statik -src=./static/dist
24+
25+
26+
Then _/statik/statik.go_ should then be updated. Rebuild Hoverfly so it is then included into binary.
27+
Commit it in order to see changes.
28+
29+

static/js/webpack.config.js renamed to static/webpack.config.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
var path = require("path");
22
var webpack = require('webpack');
3+
var CopyWebpackPlugin = require('copy-webpack-plugin');
34

45

56
module.exports = {
67
context: __dirname,
78
entry: {
8-
home: "./src/home.jsx"
9+
home: "./js/src/home.jsx"
910
},
1011
output: {
1112
path: path.resolve("./dist"),
12-
filename: "[name]-bundle.js"
13+
filename: "js/[name]-bundle.js"
1314
},
15+
plugins: [
16+
new CopyWebpackPlugin([
17+
{ from: 'index.html' },
18+
{ from: 'css', to: 'css' },
19+
{ from: 'images', to: 'images' }
20+
])
21+
],
1422

1523
module: {
1624
loaders: [

statik/statik.go

Lines changed: 10 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)