1 | ## hawtio-node-backend
|
2 |
|
3 | A simple node backend for hawtio 2.x that can either be run from a gulpfile or as an independent server. The server can serve out static assets, has a dynamic proxy and also supports configuring static proxies to backend services.
|
4 |
|
5 | ### Configuration
|
6 |
|
7 | The backend can be configured either via a config.js file:
|
8 |
|
9 | ```
|
10 | // default config values
|
11 | var config = {
|
12 | // server listen port
|
13 | port: 2772,
|
14 | // log level
|
15 | logLevel: logger.DEBUG,
|
16 | // path to mount the dyamic proxy
|
17 | proxy: '/proxy',
|
18 | // paths to connect to external services, an example config:
|
19 | // {
|
20 | // proto: 'http',
|
21 | // hostname: 'localhost',
|
22 | // port: 8282,
|
23 | // path: '/hawtio/jolokia',
|
24 | // targetPath: '/hawtio/jolokia'
|
25 | // }
|
26 | //
|
27 | staticProxies: [],
|
28 | // directories to search for static assets
|
29 | staticAssets: [
|
30 | '/assets'
|
31 | ],
|
32 | liveReload: {
|
33 | enabled: false,
|
34 | port: 35729
|
35 | }
|
36 | }
|
37 | module.exports = config;
|
38 | ```
|
39 |
|
40 | Or if using from a gulp file you can do:
|
41 |
|
42 | ```
|
43 | var HawtioBackend = require('hawtio-node-backend');
|
44 | HawtioBackend.setConfig({
|
45 | port: 2332,
|
46 | staticProxies: [{
|
47 | port: 8282,
|
48 | path: '/jolokia',
|
49 | targetPath: '/hawtio/jolokia'
|
50 | }],
|
51 | staticAssets: [{
|
52 | path: '/',
|
53 | dir: '.'
|
54 | }],
|
55 | liveReload: {
|
56 | enabled: true
|
57 | }
|
58 | });
|
59 | ```
|
60 |
|
61 | ### Full live reload gulpfile set up
|
62 |
|
63 | It's very similar to gulp-connect:
|
64 |
|
65 | ```
|
66 | var HawtioBackend = require('hawtio-node-backend');
|
67 |
|
68 | gulp.task('watch', function() {
|
69 | plugins.watch(['assets/*'], function() {
|
70 | gulp.start(['reload']);
|
71 | });
|
72 | });
|
73 |
|
74 | gulp.task('reload', function() {
|
75 | gulp.src('.')
|
76 | .pipe(HawtioBackend.reload());
|
77 | });
|
78 |
|
79 | gulp.task('server', function() {
|
80 | HawtioBackend.setConfig({
|
81 | logLevel: require('js-logger').DEBUG,
|
82 | port: 8080,
|
83 | staticProxies: [{
|
84 | port: 8282,
|
85 | path: '/hawtio/jolokia',
|
86 | targetPath: '/hawtio/jolokia'
|
87 | }],
|
88 | staticAssets: [{
|
89 | path: '/',
|
90 | dir: '.'
|
91 | }],
|
92 | liveReload: {
|
93 | enabled: true
|
94 | }
|
95 | });
|
96 | HawtioBackend.listen(function(server) {
|
97 | var host = server.address().address;
|
98 | var port = server.address().port;
|
99 | console.log("started from gulp file at ", host, ":", port);
|
100 | });
|
101 | });
|
102 |
|
103 | ```
|