-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d266e1
commit 3052781
Showing
12 changed files
with
171 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,4 @@ appveyor.yml | |
server/config.json | ||
!dashboard.service.js | ||
!webserver.js | ||
!startWebserver.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
port: 7001 ## webserver port, which you can access in web | ||
gateway: | ||
ip: 192.168.8.44 | ||
port: 8090 | ||
https: false | ||
runmode: dev | ||
stats-exporter: | ||
ip: 192.168.8.44 | ||
port: 9200 | ||
https: false | ||
node-exporter: | ||
- ip: 192.168.8.143 | ||
port: 9100 | ||
https: false | ||
prometheus: | ||
ip: 192.168.8.44 | ||
port: 9090 | ||
https: false | ||
scrape_interval: 5s | ||
evaluation_interval: 5s | ||
# the cluster node info | ||
nebula-cluster: | ||
name: 'default' # cluster name | ||
metad: | ||
- name: metad0 | ||
endpointIP: 192.168.8.143 | ||
port: 9559 | ||
endpointPort: 19559 | ||
graphd: | ||
- name: graphd0 | ||
endpointIP: 192.168.8.143 | ||
port: 9669 | ||
endpointPort: 19669 | ||
storaged: | ||
- name: storaged0 | ||
endpointIP: 192.168.8.143 | ||
port: 9779 | ||
endpointPort: 19779 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,32 @@ | ||
import express from 'express'; | ||
import webpack from 'webpack'; | ||
import webpackDevMiddleware from 'webpack-dev-middleware'; | ||
import { createProxyMiddleware } from 'http-proxy-middleware'; | ||
import history from 'connect-history-api-fallback'; | ||
import config from '../config/webpack.config.dev'; | ||
import webpackConfig from '../config/webpack.config.dev'; | ||
import yaml from 'js-yaml'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import startWebserver from '../startWebserver'; | ||
import pkg from '../package.json'; | ||
|
||
const path = require('path'); | ||
// change node config dir | ||
// process.env.NODE_CONFIG_DIR = path.resolve('./server') ; | ||
// process.env.NODE_ENV= "config"; | ||
// import _config from "config"; | ||
// _config | ||
// const port = _config.get('port'); | ||
// const nebulaServer = _config.get('nebulaServer'); | ||
// const proxy = _config.get('proxy'); | ||
const compiler = webpack(webpackConfig); | ||
|
||
const app = express(); | ||
const compiler = webpack(config); | ||
|
||
const getTargetUrl =(target)=> { | ||
return target.startsWith('http') ? target : `http://${target}` | ||
function loadYamlConfig() { | ||
const doc = yaml.load(fs.readFileSync(path.resolve(__dirname, 'config.yaml'), 'utf8')); | ||
return doc; | ||
} | ||
|
||
const config = loadYamlConfig(); | ||
|
||
const app = express(); | ||
|
||
app.use(history()); | ||
|
||
app.use( | ||
webpackDevMiddleware(compiler, { | ||
publicPath: config.output.publicPath, | ||
publicPath: webpackConfig.output.publicPath, | ||
index: 'index.html', | ||
}) | ||
); | ||
|
||
app.use('/api-metrics/*', createProxyMiddleware({ | ||
target: getTargetUrl(proxy.prometheus.target), | ||
pathRewrite: { | ||
'/api-metrics': '/api/v1', | ||
}, | ||
changeOrigin: true, | ||
})) | ||
|
||
app.use('/api-nebula/*', createProxyMiddleware({ | ||
target: getTargetUrl(proxy.gateway.target), | ||
pathRewrite: { | ||
'/api-nebula': '/api', | ||
}, | ||
changeOrigin: true, | ||
})); | ||
|
||
app.use('/api-graph/*', createProxyMiddleware({ | ||
target: getTargetUrl(proxy.graph.target), | ||
pathRewrite: { | ||
'/api-graph': '/', | ||
}, | ||
changeOrigin: true, | ||
})); | ||
|
||
app.use('/api-storage/*', createProxyMiddleware({ | ||
target: getTargetUrl(proxy.storage.target), | ||
pathRewrite: { | ||
'/api-storage': '/', | ||
}, | ||
changeOrigin: true, | ||
})); | ||
|
||
app.get('/api/app', (_req, res) => { | ||
res.send({ | ||
version: pkg.version, | ||
}) | ||
}); | ||
|
||
app.get('/api/config/custom', async (_req, res) => { | ||
if (nebulaServer) { | ||
res.send({ | ||
code: 0, | ||
data: { | ||
connection: nebulaServer, | ||
alias: { | ||
"ip:port": "instance1" | ||
}, | ||
} | ||
}); | ||
} else { | ||
res.send({ | ||
code: -1, | ||
data: null | ||
}); | ||
} | ||
}); | ||
|
||
app.listen(port, function () { | ||
console.log(`Example app listening on port ${port}!\n`); | ||
}); | ||
startWebserver(app, config, pkg.version); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
const { createProxyMiddleware } = require('http-proxy-middleware'); | ||
const chalk = require('chalk'); | ||
|
||
function INFO(...info) { | ||
console.log(chalk.green(info.join(' '))) | ||
} | ||
|
||
function getFullUrl({ https, ip, port }) { | ||
const protocol = https ? 'https' : 'http'; | ||
return `${protocol}://${ip}:${port}`; | ||
} | ||
|
||
function getServiceTarget(type, config) { | ||
const service = config['nebula-cluster']; | ||
if (!service) { | ||
throw new Error(`nebula cluster should have at least one ${type} service`); | ||
} | ||
const { endpointIP, endpointPort } = service[type][0]; | ||
if (endpointIP.startsWith('http')) { | ||
throw new Error(`endpointIP should not start with http, got ${endpointIP}`); | ||
} | ||
return `http://${endpointIP}:${endpointPort}`; | ||
} | ||
|
||
function startWebserver(app, config, version) { | ||
|
||
app.use('/api-metrics/*', createProxyMiddleware({ | ||
target: getFullUrl(config.prometheus), | ||
pathRewrite: { | ||
'/api-metrics': '/api/v1', | ||
}, | ||
changeOrigin: true, | ||
})) | ||
|
||
app.use('/api-nebula/*', createProxyMiddleware({ | ||
target: getFullUrl(config.gateway), | ||
pathRewrite: { | ||
'/api-nebula': '/api', | ||
}, | ||
changeOrigin: true, | ||
})); | ||
|
||
app.get('/api/app', (_req, res) => { | ||
res.send({ | ||
version, | ||
}) | ||
}); | ||
|
||
app.use('/api-graph/*', createProxyMiddleware({ | ||
target: getServiceTarget('graphd', config), | ||
pathRewrite: { | ||
'/api-graph': '/', | ||
}, | ||
changeOrigin: true, | ||
})); | ||
|
||
app.use('/api-storage/*', createProxyMiddleware({ | ||
target: getServiceTarget('storaged', config), | ||
pathRewrite: { | ||
'/api-storage': '/', | ||
}, | ||
changeOrigin: true, | ||
})); | ||
|
||
app.use('/api-meta/*', createProxyMiddleware({ | ||
target: getServiceTarget('metad', config), | ||
pathRewrite: { | ||
'/api-meta': '/', | ||
}, | ||
changeOrigin: true, | ||
})); | ||
|
||
app.get('/api/config/custom', async (_req, res) => { | ||
res.send({ | ||
code: 0, | ||
data: { | ||
connection: { | ||
ip: config['nebula-cluster'].graphd[0].endpointIP, | ||
port: config['nebula-cluster'].graphd[0].port | ||
}, | ||
alias: { | ||
"ip:port": getServiceTarget('graphd', config) | ||
}, | ||
} | ||
}); | ||
}); | ||
|
||
app.listen(config.port, function () { | ||
INFO(`Welcome to Nebula Dashboard!\r\nthe app is listening on port ${config.port}!\n`); | ||
}); | ||
} | ||
|
||
module.exports = startWebserver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.