add server2.js
This commit is contained in:
parent
99cc371e7b
commit
dee7cc0fdf
|
|
@ -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}`);
|
||||
});
|
||||
Loading…
Reference in New Issue