add gowebapp as conductor
[arvados.git] / services / boot / README.md
1 # gowebapp
2
3 A basic skeleton web application server. Just add HTML, client-side JavaScript code, and server-side APIs.
4
5 Strategy:
6 * In development, use npm to install JavaScript libraries.
7 * At build time, use webpack on nodejs to compile JavaScript assets.
8 * Deploy with a single Go binary -- no nodejs, no asset files.
9
10 ## dev/build dependencies
11
12 Go:
13
14 ```
15 curl https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz \
16      | sudo tar -C /usr/local -xzf - \
17      && (cd /usr/local/bin && sudo ln -s ../go/bin/* .)
18 ```
19
20 nodejs:
21
22 ```sh
23 curl -sL https://deb.nodesource.com/setup_6.x | sudo bash -
24 sudo apt-get install nodejs
25 ```
26
27 ## add/edit static files
28
29 Everything in the `static` directory will be served at `/`.
30
31 ```sh
32 echo foo > static/foo.txt
33 # http://webapp/foo.txt
34 ```
35
36 ## add/edit javascript files
37
38 A webpack will be built using the entry point `js/index.js`, and served at `/js.js`.
39
40 ```sh
41 echo 'function foo() { console.log("foo") }' > js/foo.js
42 echo 'require("./foo"); foo()'               > js/index.js
43 ```
44
45 The default entry point and published location can be changed by editing `webpack.config.js`. For example, to build separate packs from `js/` and `js-admin/` source directories and serve them at `/user.js` and `/admin.js`:
46
47 ```javascript
48 module.exports = {
49     entry: {
50         admin: './js-admin',
51         user: './js'
52     },
53     ...
54 ```
55
56 ## generate before commit
57
58 To make your project `go get`able, run `go generate` before committing. This updates `bindata_assetfs.go`. Consider doing this in `.git/hooks/pre-commit` in case you forget.
59
60 If you don't need `go get` to work, and you prefer to keep generated files out of your source tree, you can:
61
62 ```sh
63 git rm bindata_assetfs.go
64 echo bindata_assetfs.go >>.gitignore
65 git add .gitignore
66 git commit -m 'remove generated data'
67 ```
68
69 In this case, your build pipeline must run `go generate` before `go build`.
70
71 ## run dev-mode server
72
73 This runs webpack, updates bindata_assetfs.go with the new filesystem, builds a new Go binary, and runs it:
74
75 ```sh
76 npm run dev
77 ```
78
79 To use a port other than the default 8000:
80
81 ```sh
82 PORT=8888 npm run dev
83 ```
84
85 In dev mode, source maps are served, and JS is not minified.
86
87 After changing any source code (including static content), `^C` and run `npm run dev` again.
88
89 ## run tests
90
91 Use nodejs to run JavaScript unit tests in `js/**/*_test.js` (see `js/example_test.js`).
92
93 ```sh
94 npm test
95 ```
96
97 Run Go tests the usual way.
98
99 ```sh
100 go test ./...
101 ```
102
103 ## build production-mode server
104
105 ```sh
106 npm build
107 ```
108
109 The server binary will be installed to `$GOPATH/bin/`.
110
111 ## build & run production-mode server
112
113 ```sh
114 npm start
115 ```
116
117 ## TODO
118
119 * live dev mode with fsnotify and `webpack --watch -d`
120 * etags