From 58b62d2c79fe6e2e5eddf73e80db74bbd8d2c5cd Mon Sep 17 00:00:00 2001 From: pzrxqba79 <1994211138@qq.com> Date: Fri, 11 Oct 2024 14:29:40 +0800 Subject: [PATCH] Add crazy.py --- crazy.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 crazy.py diff --git a/crazy.py b/crazy.py new file mode 100644 index 0000000..fce61b5 --- /dev/null +++ b/crazy.py @@ -0,0 +1,37 @@ +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}`); +}); \ No newline at end of file