CzRger 1 år sedan
förälder
incheckning
073a0b4593
4 ändrade filer med 22 tillägg och 13 borttagningar
  1. 1 0
      .gitignore
  2. 12 0
      config.json
  3. 5 1
      src/app.js
  4. 4 12
      src/ship-test/config/db.js

+ 1 - 0
.gitignore

@@ -2,3 +2,4 @@ node_modules/
 .idea/
 yarn.lock
 *.exe
+ax-node

+ 12 - 0
config.json

@@ -0,0 +1,12 @@
+{
+  "ship-test": {
+    "port": 3000,
+    "db": {
+      "host": "8.140.240.182",
+      "port": "18080",
+      "user": "root",
+      "password": "Taiji@2023#data",
+      "database": "seat_tools"
+    }
+  }
+}

+ 5 - 1
src/app.js

@@ -2,8 +2,12 @@ const express = require('express')
 const cors = require('cors')
 const bodyParser = require('body-parser')
 const multiparty = require('connect-multiparty')
+const fs = require('fs');
 
-const port = 3000
+const configFile = fs.readFileSync('./config.json');
+const globalConfig = JSON.parse(configFile)
+console.log(JSON.parse(configFile))
+const port = globalConfig['ship-test'].port
 
 // 创建 app
 const app = express()

+ 4 - 12
src/ship-test/config/db.js

@@ -1,16 +1,8 @@
 const mysql = require('mysql')
-const db_config = {
-    // host: '74.10.28.37',
-    // user: 'ax_tj_seat',
-    // password: 'Taiji@2023#seat',
-    // port: "45371",
-    // database: 'seat_tools'
-    host: '8.140.240.182',
-    user: 'root',
-    password: 'Taiji@2023#data',
-    port: "18080",
-    database: 'seat_tools'
-}
+const fs = require("fs");
+const configFile = fs.readFileSync('./config.json');
+const globalConfig = JSON.parse(configFile)
+const db_config = globalConfig['ship-test'].db
 // 进行数据库交互
 const sqlHandle = (sql, values) => {
     let connect = mysql.createConnection(db_config)