From c074e3bf190801fe90cd067b82200ccc7d940bd2 Mon Sep 17 00:00:00 2001 From: zhl Date: Sat, 30 Jan 2021 12:52:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AA=E6=9C=89=E7=94=9F=E4=BA=A7=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=89=8D=E4=BD=BF=E7=94=A8=E6=9C=8D=E5=8A=A1=E8=87=AA?= =?UTF-8?q?=E5=8F=91=E7=8E=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/robot.ts | 8 +++++--- src/service/Service.ts | 9 ++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) 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' }