diff --git a/backend/server.js b/backend/server.js index 4e9824b..4527c11 100644 --- a/backend/server.js +++ b/backend/server.js @@ -122,7 +122,11 @@ app.use((err, req, res, next) => { res.status(500).json({ error: 'Internal server error' }); }); -app.listen(PORT, () => { +app.listen(PORT, async () => { console.log(`Server running on port ${PORT}`); console.log(`访问地址: http://localhost:${PORT}`); + + // 测试数据库连接 + const dbConfig = require('./config/database'); + await dbConfig.testConnection(); }); \ No newline at end of file diff --git a/scripts/dev.bat b/scripts/dev.bat new file mode 100644 index 0000000..1a43471 --- /dev/null +++ b/scripts/dev.bat @@ -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 diff --git a/scripts/start.bat b/scripts/start.bat new file mode 100644 index 0000000..7066fa9 --- /dev/null +++ b/scripts/start.bat @@ -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