You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
const express = require('express');
|
|
|
|
|
const morgan = require('morgan');
|
|
|
|
|
const rateLimit = require('express-rate-limit');
|
|
|
|
|
|
|
|
|
|
// 创建应用实例
|
|
|
|
|
const app = express();
|
|
|
|
|
const PORT = 3000; // 可以根据需要修改端口
|
|
|
|
|
|
|
|
|
|
// 中间件配置
|
|
|
|
|
app.use(express.json()); // 解析 JSON 格式的请求体
|
|
|
|
|
app.use(morgan('combined')); // 记录 HTTP 请求日志
|
|
|
|
|
|
|
|
|
|
// 请求限制
|
|
|
|
|
const limiter = rateLimit({
|
|
|
|
|
windowMs: 15 * 60 * 1000, // 15 分钟
|
|
|
|
|
max: 100 // 每个 IP 限制 100 次请求
|
|
|
|
|
});
|
|
|
|
|
app.use(limiter); // 应用限制
|
|
|
|
|
|
|
|
|
|
// 定义接口
|
|
|
|
|
app.post('/api/Snum-data', (req, res) => {
|
|
|
|
|
const { Number } = req.body;
|
|
|
|
|
|
|
|
|
|
// 检查请求体中的数据
|
|
|
|
|
if (typeof Number === 'undefined') {
|
|
|
|
|
return res.status(400).json({ message: 'Number is required' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('Received data:', Number);
|
|
|
|
|
// 这里可以添加数据处理逻辑,例如保存到数据库
|
|
|
|
|
res.status(200).json({ message: 'Data received successfully', data: { Number } });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 启动服务器
|
|
|
|
|
app.listen(PORT, () => {
|
|
|
|
|
console.log(`Server is running on http://localhost:${PORT}`);
|
|
|
|
|
});
|