|
|
@@ -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}`);
|