소스 검색

不同环境对应不同配置信息

DevYK 3 년 전
부모
커밋
d6de890c4f
8개의 변경된 파일179개의 추가작업 그리고 150개의 파일을 삭제
  1. 7 5
      README.md
  2. 0 101
      config/config.js
  3. 43 0
      config/dev_config.js
  4. 43 0
      config/prd_config.js
  5. 40 0
      config/test_config.js
  6. 10 14
      model/moralis_sdk.js
  7. 6 11
      model/mysql_db.js
  8. 30 19
      model/redis_db.js

+ 7 - 5
README.md

@@ -8,8 +8,8 @@ npm install
 ```
 vim ~/.bashrc
 
-export DENET_CRYPT_KEY=0IPmaec1o9FQCqGN
-export DENET_CRYPT_IV=Zh4A7bOY2ksp9oIn
+export DENET_CRYPT_KEY=aGijQgBf51VdlsED
+export DENET_CRYPT_IV=fCHyw3VJxhU4biRF
 
 source ~/.bashrc
 
@@ -17,10 +17,12 @@ source ~/.bashrc
 
 启动
 ```
-<!-- 测试环境启动 具备热更新-->
-npm run dev
+<!-- 开发环境启动 -->
+NODE_ENV=dev ./node_modules/.bin/nodemon bin/www
+<!-- 测试环境启动-->
+NODE_ENV=test pm2 start bin/www
 <!-- 线上环境启动 -->
-npm run prd
+NODE_ENV=prd pm2 start bin/www
 ```
 
 健康检查

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 101
config/config.js


+ 43 - 0
config/dev_config.js

@@ -0,0 +1,43 @@
+const cryppt_config = {
+    KEY: 'NENET_CRYPT_KEY',
+    KEY_IV: 'NENET_CRYPT_IV',
+}
+
+const reids_token_config = {
+    TOKENPRICE: 'TOKENPRICE',
+    TOKENWITHDRAW: 'TOKENWITHDRAW'
+}
+// 设置数据库配置文件
+const db_config = {
+    // 数据库配置
+    mysql: {
+        DATABASE: '',   //表名字
+        USERNAME: '',   //用户名
+        PASSWORD: '', //密码
+        DATABASE: '',
+        PORT: '3306', //连接的端口
+        HOST: 'denet-test.csi2lctklqzg.us-east-1.rds.amazonaws.com' //host
+    },
+    redis: {
+        PORT: 6379, // Redis port
+        HOST: "r-bp1ps6my7lzg8rdhwxpi.redis.rds.aliyuncs.com", // Redis host
+        USERNAME: null,
+        PASSWORD: "Wqsd@2019"
+    },
+}
+
+// 设置 moralis sdk 配置文件
+const moralis_config = {
+        SERVER_URL: "https://1frf5yebfh6r.usemoralis.com:2053/server",
+        APP_ID: "oSwDtyD9f4GD6XPZgfDCRHPqXrm2pvBUCTv2N0X8",
+        MASTER_KEY: "YbEUAR49HwBZ8R6Q8eNTNfwtStPFPcCYehJQkYcl",
+        MORALIS_SECRET: "BGlDVjy7054iLDpDcdc9AbH65rZrhj8QIhsThcwF6thNzTnbS2ft8XmM70x4jOpU",
+        DEFAULT_PRIVATE_KEY: "6084c2a5e39fa83d5a119c3a864a442e77287f4b03bad93cef38ec5f44bca630",
+}
+
+module.exports = {
+    db_config,
+    moralis_config,
+    reids_token_config,
+}
+

+ 43 - 0
config/prd_config.js

@@ -0,0 +1,43 @@
+const cryppt_config = {
+    KEY: 'NENET_CRYPT_KEY',
+    KEY_IV: 'NENET_CRYPT_IV',
+}
+
+const reids_token_config = {
+    TOKENPRICE: 'TOKENPRICE',
+    TOKENWITHDRAW: 'TOKENWITHDRAW'
+}
+// 设置数据库配置文件
+const db_config = {
+    // 数据库配置
+    mysql: {
+        DATABASE: '',   //表名字
+        USERNAME: '',   //用户名
+        PASSWORD: '', //密码
+        DATABASE: '',
+        PORT: '3306', //连接的端口
+        HOST: 'denet-test.csi2lctklqzg.us-east-1.rds.amazonaws.com' //host
+    },
+
+    redis: {
+        PORT: 6379, // Redis port
+        HOST: "denet-test.y2slbl.clustercfg.memorydb.us-east-1.amazonaws.com", // Redis host
+        USERNAME: null, // needs Redis >= 6
+        PASSWORD: null,
+    },
+}
+
+// 设置 moralis sdk 配置文件
+const moralis_config = {
+    SERVER_URL: "",
+    APP_ID: "",
+    MASTER_KEY: "",
+    MORALIS_SECRET: ""
+}
+
+module.exports = {
+    db_config,
+    moralis_config,
+    reids_token_config,
+}
+

+ 40 - 0
config/test_config.js

@@ -0,0 +1,40 @@
+const cryppt_config = {
+    KEY: 'NENET_CRYPT_KEY',
+    KEY_IV: 'NENET_CRYPT_IV',
+}
+
+const reids_token_config = {
+    TOKENPRICE: 'TOKENPRICE',
+    TOKENWITHDRAW: 'TOKENWITHDRAW'
+}
+// 设置数据库配置文件
+const db_config = {
+    mysql: {
+        PORT: 6379, // Redis port
+        HOST: "r-bp1ps6my7lzg8rdhwxpi.redis.rds.aliyuncs.com", // Redis host
+        USERNAME: null,
+        PASSWORD: "Wqsd@2019"
+    },
+
+    redis: {
+        PORT: 6379, // Redis port
+        HOST: "denet-test.y2slbl.clustercfg.memorydb.us-east-1.amazonaws.com", // Redis host
+        USERNAME: null, // needs Redis >= 6
+        PASSWORD: null,
+    },
+}
+
+// 设置 moralis sdk 配置文件
+const moralis_config = {
+    SERVER_URL: "https://1frf5yebfh6r.usemoralis.com:2053/server",
+    APP_ID: "oSwDtyD9f4GD6XPZgfDCRHPqXrm2pvBUCTv2N0X8",
+    MASTER_KEY: "YbEUAR49HwBZ8R6Q8eNTNfwtStPFPcCYehJQkYcl",
+    MORALIS_SECRET: "BGlDVjy7054iLDpDcdc9AbH65rZrhj8QIhsThcwF6thNzTnbS2ft8XmM70x4jOpU",
+    DEFAULT_PRIVATE_KEY: "6084c2a5e39fa83d5a119c3a864a442e77287f4b03bad93cef38ec5f44bca630",
+}
+module.exports = {
+    db_config,
+    moralis_config,
+    reids_token_config,
+}
+

+ 10 - 14
model/moralis_sdk.js

@@ -2,22 +2,17 @@
 const Moralis = require("moralis/node");
 
 var utils = require('./utils.js');
-var config = require('../config/config.js');
+// var config = require('../config/config.js')(db_config,
+//     moralis_config)
+var { moralis_config, reids_token_config } = require('../config/config.js')
 const redis = require("./redis_db")  //导入 db.js
 const mysql = require("./mysql_db")
 
 /* Moralis init code */
-var serverUrl = config.moralis_config.test_server.SERVER_URL;
-var appId = config.moralis_config.test_server.APP_ID;
-var masterKey = config.moralis_config.test_server.MASTER_KEY;
-var moralisSecret = config.moralis_config.test_server.MORALIS_SECRET;
-
-if (config.build_config.open_test == 0) {
-    serverUrl = config.moralis_config.main_server.SERVER_URL;
-    appId = config.moralis_config.main_server.APP_ID;
-    masterKey = config.moralis_config.main_server.MASTER_KEY;
-    moralisSecret = config.moralis_config.main_server.MORALIS_SECRET;
-}
+var serverUrl = moralis_config.SERVER_URL;
+var appId = moralis_config.APP_ID;
+var masterKey = moralis_config.MASTER_KEY;
+var moralisSecret = moralis_config.MORALIS_SECRET;
 
 // 内部异常
 const ERROR_CODE_001 = -1;
@@ -102,7 +97,7 @@ const transfer = async (obj) => {
         return toJson(-1, null, "decryptPrivityKey error.");
     }
 
-    console.log('decryptPrivityKey privateKey=',opts.privateKey)
+    console.log('decryptPrivityKey privateKey=', opts.privateKey)
     try {
         // sending 0.5 DAI tokens with 18 decimals on BSC testnet
         var options = Moralis.TransferOptions = {}
@@ -166,8 +161,9 @@ function readRedis(key) {
  */
 const getAllTotkenPrice = async () => {
     try {
+        console.log('当前环境:', process.env.NODE_ENV);
         console.log("getAllTotkenPrice in"); // Prints "value"
-        var token_price_key = config.reids_token_config.TOKENPRICE;
+        var token_price_key = reids_token_config.TOKENPRICE;
         return await readRedis(token_price_key)
     } catch (error) {
         console.error("getTotkenPrice=", error);

+ 6 - 11
model/mysql_db.js

@@ -1,16 +1,11 @@
 var mysql = require('mysql');
-var config = require('../config/config.js') // 导入位置文件
+var { db_config } = require('../config/config.js')
+
+var port = db_config.mysql.PORT
+var host = db_config.mysql.HOST
+var username = db_config.mysql.USERNAME
+var password = db_config.redis.PASSWORD
 
-var port = config.db_config.test.mysql.PORT
-var host = config.db_config.test.mysql.HOST
-var username = config.db_config.test.mysql.USERNAME
-var password = config.db_config.test.redis.PASSWORD
-if (config.build_config.open_test == 0) {
-    port = config.db_config.main.mysql.PORT
-    host = config.db_config.main.mysql.HOST
-    username = config.db_config.main.mysql.USERNAME
-    password = config.db_config.main.mysql.PASSWORD
-}
 
 // var connection = mysql.createConnection({
 //     host: host,

+ 30 - 19
model/redis_db.js

@@ -1,32 +1,43 @@
 var Redis = require('ioredis');  //导入 安装好的 redis.  npm i ioredis --save 
-var config = require('../config/config.js') // 导入位置文件
+var {db_config} = require('../config/config.js') // 导入位置文件
 
 //redis 服务启动 /usr/local/bin/redis-server /usr/local/etc/redis.conf
 
 
-var port = config.db_config.test.redis.PORT
-var host = config.db_config.test.redis.HOST
-var username = config.db_config.test.redis.USERNAME
-var password = config.db_config.test.redis.PASSWORD
-if (config.build_config.open_test == 0) {
-  port = config.db_config.main.redis.PORT
-  host = config.db_config.main.redis.HOST
-  username = config.db_config.main.redis.USERNAME
-  password = config.db_config.main.redis.PASSWORD
-}
+var port = db_config.redis.PORT
+var host = db_config.redis.HOST
+var username = db_config.redis.USERNAME
+var password = db_config.redis.PASSWORD
 
 // username: username,
 // password: password,
-console.log('host , post', host, port)
-
-const opts = {
-  port: port,
-  host: host,
-  // username: username,
-  // password: password,
-  connectTimeout: 10000,
+console.log('host , post', host, port, process.env.NODE_ENV)
+var opts;
+if (process.env.NODE_ENV == 'test') {
+  opts = {
+    port: port,
+    host: host,
+    connectTimeout: 10000,
+  }
+} else if (process.env.NODE_ENV == 'dev') {
+  opts = {
+    port: port,
+    host: host,
+    username: username,
+    password: password,
+    connectTimeout: 10000,
+  }
+} else if (process.env.NODE_ENV == 'prd') {
+  opts = {
+    port: port,
+    host: host,
+    username: username,
+    password: password,
+    connectTimeout: 10000,
+  }
 }
 
+
 var REDIS_INSTANCE = new Redis(opts);
 
 REDIS_INSTANCE.on('connect', () => {

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.