diff --git a/src/robot.ts b/src/robot.ts index 7989dc6..82eb9c0 100644 --- a/src/robot.ts +++ b/src/robot.ts @@ -19,7 +19,7 @@ const app = express() const port = Number(process.env.PORT || 2500); let config: Config = require('../config/config.json'); - +const isProd = process.env.NODE_ENV === 'production' initData(); app.use(cors()); app.use(express.json()); @@ -37,7 +37,9 @@ let opts = {url: config.redis} new RedisClient(opts) app.listen(port, async function () { - await registerGracefulShutdown((err) => gracefullyShutdown(true, err)); - await registService(port) + if (isProd) { + await registerGracefulShutdown((err) => gracefullyShutdown(true, err)); + await registService(port) + } console.log(`App is listening on port ${port}!`); }); diff --git a/src/service/Service.ts b/src/service/Service.ts index e1c5eb1..3062880 100644 --- a/src/service/Service.ts +++ b/src/service/Service.ts @@ -4,6 +4,7 @@ import { error, sysLog } from '../common/Debug' import { Config } from '../cfg/Config' import ip from 'internal-ip' const config: Config = require('../../config/config.json') +const isProd = process.env.NODE_ENV === 'production' @singleton export class Service { /** @@ -35,7 +36,9 @@ export class Service { constructor() { this.serviceMap.set(Service.INFO_NODE, []) this.serviceMap.set(Service.ROBOT_NODE, []) - this.discoveryServices() + if (isProd) { + this.discoveryServices() + } } public discoveryServices() { @@ -74,7 +77,7 @@ export class Service { this.serviceMap.set(key, svrList) } let svrList = this.serviceMap.get(key) - if (svrList.length == 0) { + if (svrList.length == 0 || !isProd) { error('no info service found') return config.info_svr } @@ -88,7 +91,7 @@ export class Service { this.serviceMap.set(key, svrList) } let svrList = this.serviceMap.get(key) - if (svrList.length == 0) { + if (svrList.length == 0 || !isProd) { error('no robot service found') return 'http://127.0.0.1:2500' }