添加 IntelliJ IDEA 项目配置文件
This commit is contained in:
@@ -4,6 +4,8 @@ const helmet = require('helmet')
|
||||
const morgan = require('morgan')
|
||||
const rateLimit = require('express-rate-limit')
|
||||
const compression = require('compression')
|
||||
const { testConnection, syncDatabase } = require('./config/database')
|
||||
const { createInitialUsers } = require('./scripts/initData')
|
||||
require('dotenv').config()
|
||||
|
||||
const app = express()
|
||||
@@ -69,10 +71,33 @@ app.use((err, req, res, next) => {
|
||||
|
||||
const PORT = process.env.PORT || 3000
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`🚀 服务器启动成功`)
|
||||
console.log(`📱 运行环境: ${process.env.NODE_ENV || 'development'}`)
|
||||
console.log(`🌐 访问地址: http://localhost:${PORT}`)
|
||||
console.log(`📊 健康检查: http://localhost:${PORT}/health`)
|
||||
console.log(`📚 API文档: http://localhost:${PORT}/api/docs`)
|
||||
})
|
||||
// 启动服务器
|
||||
const startServer = async () => {
|
||||
try {
|
||||
// 测试数据库连接
|
||||
const dbConnected = await testConnection();
|
||||
if (!dbConnected) {
|
||||
console.log('⚠️ 数据库连接失败,使用模拟数据模式');
|
||||
} else {
|
||||
// 同步数据库模型(开发环境)
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
await syncDatabase({ alter: true });
|
||||
// 创建初始用户数据
|
||||
await createInitialUsers();
|
||||
}
|
||||
}
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`🚀 服务器启动成功`)
|
||||
console.log(`📱 运行环境: ${process.env.NODE_ENV || 'development'}`)
|
||||
console.log(`🌐 访问地址: http://localhost:${PORT}`)
|
||||
console.log(`📊 健康检查: http://localhost:${PORT}/health`)
|
||||
console.log(`📚 API文档: http://localhost:${PORT}/api/docs`)
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('❌ 服务器启动失败:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
startServer();
|
||||
Reference in New Issue
Block a user