feat(server): 添加数据库连接测试并优化启动脚本
添加了服务器启动时的数据库连接测试功能,确保数据库可用性 新增 start.bat 和 dev.bat 脚本用于简化开发和生产环境启动 脚本会自动检查端口占用并处理依赖安装
This commit is contained in:
@@ -122,7 +122,11 @@ app.use((err, req, res, next) => {
|
|||||||
res.status(500).json({ error: 'Internal server error' });
|
res.status(500).json({ error: 'Internal server error' });
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, async () => {
|
||||||
console.log(`Server running on port ${PORT}`);
|
console.log(`Server running on port ${PORT}`);
|
||||||
console.log(`访问地址: http://localhost:${PORT}`);
|
console.log(`访问地址: http://localhost:${PORT}`);
|
||||||
|
|
||||||
|
// 测试数据库连接
|
||||||
|
const dbConfig = require('./config/database');
|
||||||
|
await dbConfig.testConnection();
|
||||||
});
|
});
|
||||||
26
scripts/dev.bat
Normal file
26
scripts/dev.bat
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
@echo off
|
||||||
|
setlocal enabledelayedexpansion
|
||||||
|
|
||||||
|
echo Checking if WebWork is already running...
|
||||||
|
|
||||||
|
:: 查找占用 3000 端口的进程 PID
|
||||||
|
for /f "tokens=5" %%a in ('netstat -ano ^| findstr :3000 ^| findstr LISTENING') do (
|
||||||
|
set PID=%%a
|
||||||
|
if not "!PID!"=="" (
|
||||||
|
echo Port 3000 is already in use by PID !PID!. Killing process...
|
||||||
|
taskkill /F /PID !PID!
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Starting WebWork System in Development Mode...
|
||||||
|
|
||||||
|
cd ..\backend
|
||||||
|
|
||||||
|
if not exist node_modules (
|
||||||
|
echo node_modules not found, installing dependencies...
|
||||||
|
call npm install
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Starting Backend Server with nodemon...
|
||||||
|
start http://localhost:3000
|
||||||
|
npm run dev
|
||||||
26
scripts/start.bat
Normal file
26
scripts/start.bat
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
@echo off
|
||||||
|
setlocal enabledelayedexpansion
|
||||||
|
|
||||||
|
echo Checking if WebWork is already running...
|
||||||
|
|
||||||
|
:: 查找占用 3000 端口的进程 PID
|
||||||
|
for /f "tokens=5" %%a in ('netstat -ano ^| findstr :3000 ^| findstr LISTENING') do (
|
||||||
|
set PID=%%a
|
||||||
|
if not "!PID!"=="" (
|
||||||
|
echo Port 3000 is already in use by PID !PID!. Killing process...
|
||||||
|
taskkill /F /PID !PID!
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Starting WebWork System...
|
||||||
|
|
||||||
|
cd ..\backend
|
||||||
|
|
||||||
|
if not exist node_modules (
|
||||||
|
echo node_modules not found, installing dependencies...
|
||||||
|
call npm install
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Starting Backend Server...
|
||||||
|
start http://localhost:3000
|
||||||
|
npm start
|
||||||
Reference in New Issue
Block a user