只有生产环境才使用服务自发现功能
This commit is contained in:
parent
7d07e29720
commit
c074e3bf19
@ -19,7 +19,7 @@ const app = express()
|
|||||||
const port = Number(process.env.PORT || 2500);
|
const port = Number(process.env.PORT || 2500);
|
||||||
|
|
||||||
let config: Config = require('../config/config.json');
|
let config: Config = require('../config/config.json');
|
||||||
|
const isProd = process.env.NODE_ENV === 'production'
|
||||||
initData();
|
initData();
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
@ -37,7 +37,9 @@ let opts = {url: config.redis}
|
|||||||
new RedisClient(opts)
|
new RedisClient(opts)
|
||||||
|
|
||||||
app.listen(port, async function () {
|
app.listen(port, async function () {
|
||||||
await registerGracefulShutdown((err) => gracefullyShutdown(true, err));
|
if (isProd) {
|
||||||
await registService(port)
|
await registerGracefulShutdown((err) => gracefullyShutdown(true, err));
|
||||||
|
await registService(port)
|
||||||
|
}
|
||||||
console.log(`App is listening on port ${port}!`);
|
console.log(`App is listening on port ${port}!`);
|
||||||
});
|
});
|
||||||
|
@ -4,6 +4,7 @@ import { error, sysLog } from '../common/Debug'
|
|||||||
import { Config } from '../cfg/Config'
|
import { Config } from '../cfg/Config'
|
||||||
import ip from 'internal-ip'
|
import ip from 'internal-ip'
|
||||||
const config: Config = require('../../config/config.json')
|
const config: Config = require('../../config/config.json')
|
||||||
|
const isProd = process.env.NODE_ENV === 'production'
|
||||||
@singleton
|
@singleton
|
||||||
export class Service {
|
export class Service {
|
||||||
/**
|
/**
|
||||||
@ -35,7 +36,9 @@ export class Service {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.serviceMap.set(Service.INFO_NODE, [])
|
this.serviceMap.set(Service.INFO_NODE, [])
|
||||||
this.serviceMap.set(Service.ROBOT_NODE, [])
|
this.serviceMap.set(Service.ROBOT_NODE, [])
|
||||||
this.discoveryServices()
|
if (isProd) {
|
||||||
|
this.discoveryServices()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public discoveryServices() {
|
public discoveryServices() {
|
||||||
@ -74,7 +77,7 @@ export class Service {
|
|||||||
this.serviceMap.set(key, svrList)
|
this.serviceMap.set(key, svrList)
|
||||||
}
|
}
|
||||||
let svrList = this.serviceMap.get(key)
|
let svrList = this.serviceMap.get(key)
|
||||||
if (svrList.length == 0) {
|
if (svrList.length == 0 || !isProd) {
|
||||||
error('no info service found')
|
error('no info service found')
|
||||||
return config.info_svr
|
return config.info_svr
|
||||||
}
|
}
|
||||||
@ -88,7 +91,7 @@ export class Service {
|
|||||||
this.serviceMap.set(key, svrList)
|
this.serviceMap.set(key, svrList)
|
||||||
}
|
}
|
||||||
let svrList = this.serviceMap.get(key)
|
let svrList = this.serviceMap.get(key)
|
||||||
if (svrList.length == 0) {
|
if (svrList.length == 0 || !isProd) {
|
||||||
error('no robot service found')
|
error('no robot service found')
|
||||||
return 'http://127.0.0.1:2500'
|
return 'http://127.0.0.1:2500'
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user