add server2.js

This commit is contained in:
cys 2024-07-07 23:38:24 +08:00
parent 99cc371e7b
commit dee7cc0fdf
1 changed files with 41 additions and 0 deletions

41
public/server2.js Normal file
View File

@ -0,0 +1,41 @@
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = 8000;
// 假设这是模拟的表格数据
let tableData = [
{ id: 1, type: 'A', table_id: 1001, clue_id: 2001, del_time: '2024-06-20' },
{ id: 2, type: 'B', table_id: 1002, clue_id: 2002, del_time: '2024-06-21' },
{ id: 27, type: 'C', table_id: 1003, clue_id: 2003, del_time: '2024-06-22' }
];
app.use(bodyParser.json());
// CORS 中间件
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
// 获取表格数据的API
app.get('/showDelRecords/', (req, res) => {
res.json({ message:'数据',data: tableData });
});
// 处理撤销操作的API
app.post('/withDraw/', (req, res) => {
const { id } = req.body;
// 根据 ID 删除对应的数据
tableData = tableData.filter(row => row.id !== id);
res.json({ message: '成功撤销数据' });
});
// 启动服务器
app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
});