This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
constexpress=require('express');
constmorgan=require('morgan');
constrateLimit=require('express-rate-limit');
//创建应用实例
constapp=express();
constPORT=3000;//可以根据需要修改端口
//中间件配置
app.use(express.json());//解析JSON格式的请求体
app.use(morgan('combined'));//记录HTTP请求日志
//请求限制
constlimiter=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(typeofNumber==='undefined'){
returnres.status(400).json({message:'Number is required'});
}
console.log('Received data:',Number);
//这里可以添加数据处理逻辑,例如保存到数据库
res.status(200).json({message:'Data received successfully',data:{Number}});