明树Git Lab

Commit 22947a0c authored by zhangqi's avatar zhangqi

add db info

parent 1d6b5e7c
...@@ -5,5 +5,13 @@ ...@@ -5,5 +5,13 @@
"storagePath": "/mnt/vdb1/uploadfiles" "storagePath": "/mnt/vdb1/uploadfiles"
}, },
"cron": { "cron": {
},
"mysql": {
"host": "127.0.0.1",
"port": 3306,
"username": "root",
"password": "zhangqi1997.",
"database": "gzbjt",
"logging": true
} }
} }
\ No newline at end of file
// db.js // db.js
const { Sequelize } = require('sequelize'); const { Sequelize } = require('sequelize');
const config = require('config');
const mysqlConfig = config.get('mysql');
const { database, username, password, host } = mysqlConfig
// 创建 Sequelize 实例,连接数据库 // 创建 Sequelize 实例,连接数据库
const sequelize = new Sequelize('gzbjt', 'root', '123456', { const sequelize = new Sequelize(database, username, password || '123456', {
host: 'localhost', host: host || '127.0.0.1',
dialect: 'mysql', dialect: 'mysql',
logging: console.log, // 显示日志(可选) logging: console.log, // 显示日志(可选)
pool: { pool: {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
"dependencies": { "dependencies": {
"axios": "1.7.4", "axios": "1.7.4",
"compression": "1.7.4", "compression": "1.7.4",
"config": "^4.1.1",
"cors": "2.8.5", "cors": "2.8.5",
"crypto": "1.0.1", "crypto": "1.0.1",
"crypto-js": "^4.2.0", "crypto-js": "^4.2.0",
......
...@@ -71,7 +71,10 @@ app.use(function (err, req, res, next) { ...@@ -71,7 +71,10 @@ app.use(function (err, req, res, next) {
const server = require('http').createServer(app); const server = require('http').createServer(app);
const config = require('config');
const mysqlConfig = config.get('mysql');
console.log(mysqlConfig.host)
server.listen(process.env.PORT || 3000, function () { server.listen(process.env.PORT || 3000, function () {
console.log(`****** server is listening : ${process.env.PORT} || 3000`); console.log(`****** server is listening : ${process.env.PORT} || 3000`);
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment