删除不需要的文件
This commit is contained in:
@@ -1,120 +0,0 @@
|
|||||||
const express = require('express');
|
|
||||||
const router = express.Router();
|
|
||||||
|
|
||||||
// 模拟机型数据库(实际项目中应使用真实数据库)
|
|
||||||
const aircrafts = [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
name: '波音737',
|
|
||||||
code: 'B737',
|
|
||||||
manufacturer: '波音公司',
|
|
||||||
type: '窄体客机',
|
|
||||||
description: '波音737是波音公司生产的中短程双发窄体客机,是全球最畅销的商用喷气式客机。',
|
|
||||||
specifications: {
|
|
||||||
maxPassengers: 215,
|
|
||||||
maxRange: '5700km',
|
|
||||||
cruiseSpeed: '840km/h',
|
|
||||||
length: '39.5m',
|
|
||||||
wingspan: '35.8m'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
name: '空客A320',
|
|
||||||
code: 'A320',
|
|
||||||
manufacturer: '空中客车公司',
|
|
||||||
type: '窄体客机',
|
|
||||||
description: '空客A320是空中客车公司生产的单通道窄体客机,是空客最成功的机型之一。',
|
|
||||||
specifications: {
|
|
||||||
maxPassengers: 180,
|
|
||||||
maxRange: '6150km',
|
|
||||||
cruiseSpeed: '840km/h',
|
|
||||||
length: '37.57m',
|
|
||||||
wingspan: '35.8m'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
name: '波音787',
|
|
||||||
code: 'B787',
|
|
||||||
manufacturer: '波音公司',
|
|
||||||
type: '宽体客机',
|
|
||||||
description: '波音787梦想客机是波音公司生产的双发宽体中远程客机,采用大量复合材料。',
|
|
||||||
specifications: {
|
|
||||||
maxPassengers: 330,
|
|
||||||
maxRange: '15700km',
|
|
||||||
cruiseSpeed: '913km/h',
|
|
||||||
length: '57m',
|
|
||||||
wingspan: '60m'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 4,
|
|
||||||
name: '空客A350',
|
|
||||||
code: 'A350',
|
|
||||||
manufacturer: '空中客车公司',
|
|
||||||
type: '宽体客机',
|
|
||||||
description: '空客A350是空中客车公司生产的双发宽体远程客机,采用先进材料和设计。',
|
|
||||||
specifications: {
|
|
||||||
maxPassengers: 440,
|
|
||||||
maxRange: '15000km',
|
|
||||||
cruiseSpeed: '903km/h',
|
|
||||||
length: '66.8m',
|
|
||||||
wingspan: '64.75m'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
// 获取所有机型列表
|
|
||||||
router.get('/list', (req, res) => {
|
|
||||||
try {
|
|
||||||
const { search } = req.query;
|
|
||||||
|
|
||||||
let filteredAircrafts = aircrafts;
|
|
||||||
if (search) {
|
|
||||||
const searchLower = search.toLowerCase();
|
|
||||||
filteredAircrafts = aircrafts.filter(aircraft =>
|
|
||||||
aircraft.name.toLowerCase().includes(searchLower) ||
|
|
||||||
aircraft.code.toLowerCase().includes(searchLower) ||
|
|
||||||
aircraft.manufacturer.toLowerCase().includes(searchLower)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
res.json({
|
|
||||||
success: true,
|
|
||||||
data: filteredAircrafts.map(aircraft => ({
|
|
||||||
id: aircraft.id,
|
|
||||||
name: aircraft.name,
|
|
||||||
code: aircraft.code,
|
|
||||||
manufacturer: aircraft.manufacturer,
|
|
||||||
type: aircraft.type
|
|
||||||
}))
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('获取机型列表错误:', error);
|
|
||||||
res.status(500).json({ error: '服务器内部错误' });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 获取单个机型详细信息
|
|
||||||
router.get('/:id', (req, res) => {
|
|
||||||
try {
|
|
||||||
const id = parseInt(req.params.id);
|
|
||||||
const aircraft = aircrafts.find(a => a.id === id);
|
|
||||||
|
|
||||||
if (!aircraft) {
|
|
||||||
return res.status(404).json({ error: '机型不存在' });
|
|
||||||
}
|
|
||||||
|
|
||||||
res.json({
|
|
||||||
success: true,
|
|
||||||
data: aircraft
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('获取机型详情错误:', error);
|
|
||||||
res.status(500).json({ error: '服务器内部错误' });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = router;
|
|
||||||
|
|
||||||
14
server.js
14
server.js
@@ -2,9 +2,8 @@ const express = require('express');
|
|||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const authRoutes = require('./routes/auth');
|
const authRoutes = require('./routes/auth');
|
||||||
const aircraftRoutes = require('./routes/aircraft');
|
const pdfRoutes = require('./routes/pdf');
|
||||||
const pdfRoutes = require('./routes/pdf');
|
const docsRoutes = require('./routes/docs');
|
||||||
const docsRoutes = require('./routes/docs');
|
|
||||||
const { authenticateToken } = require('./middleware/auth');
|
const { authenticateToken } = require('./middleware/auth');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
@@ -18,11 +17,10 @@ app.use(express.urlencoded({ extended: true }));
|
|||||||
// 静态文件服务 - 用于提供PDF文件
|
// 静态文件服务 - 用于提供PDF文件
|
||||||
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));
|
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));
|
||||||
|
|
||||||
// 路由
|
// 路由
|
||||||
app.use('/api/auth', authRoutes);
|
app.use('/api/auth', authRoutes);
|
||||||
app.use('/api/aircraft', authenticateToken, aircraftRoutes);
|
app.use('/api/pdf', authenticateToken, pdfRoutes);
|
||||||
app.use('/api/pdf', authenticateToken, pdfRoutes);
|
app.use('/api/docs', docsRoutes);
|
||||||
app.use('/api/docs', docsRoutes);
|
|
||||||
|
|
||||||
// 健康检查
|
// 健康检查
|
||||||
app.get('/api/health', (req, res) => {
|
app.get('/api/health', (req, res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user