Skip to content

Commit

Permalink
mod: config yaml (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolaCage authored Jan 19, 2022
1 parent 80d4318 commit 58f34ef
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion server/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ proxy:
prometheus:
target: "192.168.8.157:9090"
nebulaServer:
ip: "192.168.8.145",
ip: "192.168.8.145"
port: 9669

24 changes: 19 additions & 5 deletions server/dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@ import webpackDevMiddleware from 'webpack-dev-middleware';
import { createProxyMiddleware } from 'http-proxy-middleware';
import history from 'connect-history-api-fallback';
import fs from 'fs';
import path from 'path';

import path from "path";
const yaml = require('js-yaml');
import config from '../config/webpack.config.dev';
import pkg from '../package.json';

let _config = {} as any;
try {
let fileContents = fs.readFileSync(path.join(__dirname, './config.yaml'), 'utf8');
_config = yaml.load(fileContents);
} catch (e) {
console.log(e);
throw new Error();
}

const app = express();
const compiler = webpack(config);
const { nebulaServer } = _config;

app.use(history());

Expand Down Expand Up @@ -44,11 +54,15 @@ app.get('/api/app', (_req, res) => {
});

app.get('/api/config/custom', async (_req, res) => {
const data = await fs.readFileSync(path.join(__dirname, '../static/custom.json'), 'utf8');
if (data) {
if (nebulaServer) {
res.send({
code: 0,
data: JSON.parse(data)
data: {
connection: nebulaServer,
alias: {
"ip:port": "instance1"
},
}
});
} else {
res.send({
Expand Down
4 changes: 2 additions & 2 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const pkg = require('../package.json');
const yaml = require('js-yaml');
let config = {};
try {
let fileContents = fs.readFileSync('config.yaml', 'utf8');
let fileContents = fs.readFileSync(path.join(__dirname, './config.yaml'), 'utf8');
config = yaml.load(fileContents);
} catch (e) {
console.log(e);
Expand Down Expand Up @@ -56,7 +56,7 @@ app.get('/api/app', (_req, res) => {
});

app.get('/api/config/custom', async (_req, res) => {
if (data) {
if (nebulaServer) {
res.send({
code: 0,
data: {
Expand Down

0 comments on commit 58f34ef

Please sign in to comment.