Эх сурвалжийг харах

Update files: server/index.js

D8D AI 1 жил өмнө
parent
commit
7b54d03eb2
1 өөрчлөгдсөн 11 нэмэгдсэн , 3 устгасан
  1. 11 3
      server/index.js

+ 11 - 3
server/index.js

@@ -11,9 +11,12 @@ app.use(cors());
 app.use(express.json());
 
 // 连接到MongoDB数据库
-mongoose.connect(process.env.MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true })
-  .then(() => console.log('Connected to MongoDB'))
-  .catch(err => console.error('Could not connect to MongoDB:', err));
+mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost/member-attendance', { 
+  useNewUrlParser: true, 
+  useUnifiedTopology: true 
+})
+.then(() => console.log('Connected to MongoDB'))
+.catch(err => console.error('Could not connect to MongoDB:', err));
 
 // 示例路由:下发人员信息
 app.post('/api/publish-person-info', (req, res) => {
@@ -22,6 +25,11 @@ app.post('/api/publish-person-info', (req, res) => {
   res.json({ message: 'Person info published to MQTT' });
 });
 
+// 添加一个简单的GET路由用于测试
+app.get('/', (req, res) => {
+  res.send('Member Attendance System API is running');
+});
+
 const PORT = process.env.PORT || 5000;
 app.listen(PORT, () => {
   console.log(`Server running on port ${PORT}`);