feat: 初始化多个小程序和前端项目
- 新建多个小程序的 app.js、app.json 和 app.wxss 文件 - 新建多个前端项目的 App.vue 文件 - 添加 .gitignore 文件和后端 API 的 .env.example 文件
This commit is contained in:
48
backend/api/server.js
Normal file
48
backend/api/server.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const helmet = require('helmet');
|
||||
const dotenv = require('dotenv');
|
||||
const rateLimit = require('express-rate-limit');
|
||||
|
||||
// 加载环境变量
|
||||
dotenv.config();
|
||||
|
||||
// 创建Express应用
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 8000;
|
||||
|
||||
// 中间件
|
||||
app.use(helmet()); // 安全头部
|
||||
app.use(cors()); // 跨域支持
|
||||
app.use(express.json({ limit: '10mb' })); // JSON解析
|
||||
app.use(express.urlencoded({ extended: true, limit: '10mb' })); // URL编码解析
|
||||
|
||||
// 速率限制
|
||||
const limiter = rateLimit({
|
||||
windowMs: 15 * 60 * 1000, // 15分钟
|
||||
max: 100, // 限制每个IP 15分钟内最多100个请求
|
||||
message: '请求过于频繁,请稍后再试'
|
||||
});
|
||||
app.use(limiter);
|
||||
|
||||
// 基础路由
|
||||
app.get('/', (req, res) => {
|
||||
res.json({
|
||||
message: '欢迎使用锡林郭勒盟安格斯牛数字化管理平台API服务',
|
||||
version: '1.0.0'
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/health', (req, res) => {
|
||||
res.json({
|
||||
status: 'OK',
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
});
|
||||
|
||||
// 启动服务器
|
||||
app.listen(PORT, () => {
|
||||
console.log(`API服务器正在端口 ${PORT} 上运行`);
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
Reference in New Issue
Block a user