Files
nanocode/wanandroid/uniapp_android/server_with_projects.js
T
Ubuntu 32b43f85bd a
2026-07-03 16:58:28 +08:00

987 lines
28 KiB
JavaScript

#!/usr/bin/env node
/**
* Uniapp Material Design项目开发服务器 - 包含项目API
* 绑定到所有IP地址,支持公网访问
*/
const express = require('express');
const cors = require('cors');
const path = require('path');
const fs = require('fs');
// 创建Express应用
const app = express();
const PORT = process.env.PORT || 8000;
const HOST = '0.0.0.0'; // 绑定到所有IP
// 启用CORS
app.use(cors());
// 解析JSON请求体
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// 静态文件服务
app.use(express.static(path.join(__dirname)));
// 模拟Uniapp的页面路由
app.get('/pages/:page/:page', (req, res) => {
const pagePath = path.join(__dirname, 'pages', req.params.page, `${req.params.page}.vue`);
if (fs.existsSync(pagePath)) {
// 如果是Vue文件,返回一个简单的HTML页面
res.send(`
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>玩Android - ${req.params.page}</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Roboto', sans-serif; background: #F5F5F5; }
.container { max-width: 750px; margin: 0 auto; background: white; min-height: 100vh; }
.header { background: #6200EE; color: white; padding: 40px 20px; text-align: center; }
.content { padding: 40px 20px; text-align: center; }
.icon { font-size: 80px; color: #6200EE; margin-bottom: 24px; }
.title { font-size: 28px; font-weight: 500; margin-bottom: 12px; color: #212121; }
.desc { font-size: 16px; color: #757575; margin-bottom: 32px; line-height: 1.6; }
.info { background: #F5F5F5; padding: 20px; border-radius: 12px; margin-top: 32px; text-align: left; }
.info-title { font-size: 16px; font-weight: 500; margin-bottom: 12px; color: #6200EE; }
.info-item { margin-bottom: 8px; font-size: 14px; color: #616161; }
.btn { display: inline-block; background: #6200EE; color: white; padding: 12px 24px; border-radius: 24px; text-decoration: none; margin-top: 20px; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>玩Android Material Design</h1>
<p>开发服务器预览</p>
</div>
<div class="content">
<div class="icon">📱</div>
<div class="title">${req.params.page}页面</div>
<div class="desc">这是Uniapp Material Design项目的${req.params.page}页面预览</div>
<div class="info">
<div class="info-title">服务器信息</div>
<div class="info-item">页面路径: /pages/${req.params.page}/${req.params.page}.vue</div>
<div class="info-item">服务器地址: ${req.protocol}://${req.get('host')}</div>
<div class="info-item">公网IP: 129.211.173.87:${PORT}</div>
<div class="info-item">访问时间: ${new Date().toLocaleString()}</div>
</div>
<a href="/" class="btn">返回首页</a>
</div>
</div>
</body>
</html>
`);
} else {
res.status(404).send('页面不存在');
}
});
// 首页路由 - 使用新的首页
app.get('/', (req, res) => {
const indexPath = path.join(__dirname, 'index.html');
if (fs.existsSync(indexPath)) {
res.sendFile(indexPath);
} else {
// 如果index.html不存在,返回默认首页
res.send(`
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>玩Android Material Design - 首页</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Roboto', 'Noto Sans SC', sans-serif; background: #F5F5F5; }
.container { max-width: 750px; margin: 0 auto; background: white; min-height: 100vh; }
.header { background: #6200EE; color: white; padding: 40px 20px; text-align: center; }
.content { padding: 40px 20px; text-align: center; }
.icon { font-size: 80px; color: #6200EE; margin-bottom: 24px; }
.title { font-size: 28px; font-weight: 500; margin-bottom: 12px; color: #212121; }
.desc { font-size: 16px; color: #757575; margin-bottom: 32px; line-height: 1.6; }
.info { background: #F5F5F5; padding: 20px; border-radius: 12px; margin-top: 32px; text-align: left; }
.info-title { font-size: 16px; font-weight: 500; margin-bottom: 12px; color: #6200EE; }
.info-item { margin-bottom: 8px; font-size: 14px; color: #616161; }
.btn { display: inline-block; background: #6200EE; color: white; padding: 12px 24px; border-radius: 24px; text-decoration: none; margin-top: 20px; margin-right: 12px; }
.btn-secondary { background: #03DAC6; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>玩Android Material Design</h1>
<p>开发服务器预览</p>
</div>
<div class="content">
<div class="icon">📱</div>
<div class="title">玩Android Material Design</div>
<div class="desc">基于Uniapp框架开发的玩Android客户端,完全遵循Material Design 3设计规范</div>
<div class="info">
<div class="info-title">服务器信息</div>
<div class="info-item">服务器地址: ${req.protocol}://${req.get('host')}</div>
<div class="info-item">公网IP: 129.211.173.87:${PORT}</div>
<div class="info-item">项目路径: /home/ubuntu/wanandroid/uniapp_android</div>
<div class="info-item">启动时间: ${new Date().toLocaleString()}</div>
<div class="info-item">Node版本: ${process.version}</div>
</div>
<div style="margin-top: 32px;">
<a href="/index_correct.html" class="btn">查看正确首页</a>
<a href="/projects.html" class="btn btn-secondary">查看项目页面</a>
<a href="/material_preview.html" class="btn">Material预览</a>
</div>
</div>
</div>
</body>
</html>
`);
}
});
// API模拟 - 玩Android API
// Banner数据
app.get('/api/banner/json', (req, res) => {
res.json({
data: [
{
desc: "Material Design Banner 1",
id: 1,
imagePath: "https://via.placeholder.com/300x150/6200EE/ffffff?text=Banner1",
isVisible: 1,
order: 0,
title: "玩Android Material Design",
type: 0,
url: "https://www.wanandroid.com"
},
{
desc: "Material Design Banner 2",
id: 2,
imagePath: "https://via.placeholder.com/300x150/03DAC6/ffffff?text=Banner2",
isVisible: 1,
order: 1,
title: "Uniapp开发框架",
type: 0,
url: "https://uniapp.dcloud.io"
},
{
desc: "Material Design Banner 3",
id: 3,
imagePath: "https://via.placeholder.com/300x150/FF9800/ffffff?text=Banner3",
isVisible: 1,
order: 2,
title: "Android应用开发",
type: 0,
url: "https://developer.android.com"
}
],
errorCode: 0,
errorMsg: ""
});
});
// 搜索热词
app.get('/api/hotkey/json', (req, res) => {
res.json({
data: [
{ id: 1, link: "", name: "Material Design", order: 1, visible: 1 },
{ id: 2, link: "", name: "Uniapp", order: 2, visible: 1 },
{ id: 3, link: "", name: "Android", order: 3, visible: 1 },
{ id: 4, link: "", name: "Vue 3", order: 4, visible: 1 },
{ id: 5, link: "", name: "玩Android", order: 5, visible: 1 },
{ id: 6, link: "", name: "API开发", order: 6, visible: 1 }
],
errorCode: 0,
errorMsg: ""
});
});
// 文章列表 - 根据页码返回不同内容
app.get('/api/article/list/:page/json', (req, res) => {
const page = parseInt(req.params.page) || 0;
// 基础文章(第0页显示)
const baseArticles = [
{
id: 1,
title: "玩Android Material Design客户端发布",
link: "https://www.wanandroid.com",
author: "Material Design",
shareUser: "",
chapterName: "前端开发",
superChapterName: "移动开发",
niceDate: "刚刚",
publishTime: Date.now(),
collect: false,
zan: 42,
fresh: true,
tags: []
},
{
id: 2,
title: "Uniapp框架Material Design实践指南",
link: "https://uniapp.dcloud.io",
author: "Uniapp团队",
shareUser: "",
chapterName: "Uniapp",
superChapterName: "跨端开发",
niceDate: "1小时前",
publishTime: Date.now() - 3600000,
collect: true,
zan: 28,
fresh: false,
tags: []
},
{
id: 3,
title: "Android Material Design 3新特性详解",
link: "https://developer.android.com",
author: "Google",
shareUser: "",
chapterName: "Android",
superChapterName: "移动开发",
niceDate: "3小时前",
publishTime: Date.now() - 10800000,
collect: false,
zan: 56,
fresh: false,
tags: []
},
{
id: 4,
title: "玩Android API接口完整文档",
link: "https://www.wanandroid.com/blog/show/2",
author: "玩Android",
shareUser: "",
chapterName: "API文档",
superChapterName: "开发资源",
niceDate: "1天前",
publishTime: Date.now() - 86400000,
collect: true,
zan: 89,
fresh: false,
tags: []
}
];
// 根据页码生成动态文章
const categories = ["Kotlin", "Jetpack", "Compose", "架构", "性能", "安全", "测试", "工具", "Flutter", "ReactNative"];
const authors = ["Android团队", "Kotlin专家", "架构师", "开发者", "技术博主", "Google开发者", "开源社区", "高级工程师"];
const dynamicArticles = [];
for (let i = 0; i < 5; i++) {
const articleId = page * 10 + i + 100;
const category = categories[(page + i) % categories.length];
const author = authors[(page + i) % authors.length];
dynamicArticles.push({
id: articleId,
title: `${category}开发实战教程 - 第${page + 1}期-${i + 1}`,
link: "https://www.wanandroid.com",
author: author,
shareUser: "",
chapterName: category,
superChapterName: "技术教程",
niceDate: `${page + 1}天前`,
publishTime: Date.now() - (page * 86400000 + i * 3600000),
collect: (articleId % 2 === 0),
zan: 20 + (articleId % 50),
fresh: (page === 0 && i < 2),
tags: []
});
}
// 合并文章列表
let allArticles;
if (page === 0) {
allArticles = [...baseArticles, ...dynamicArticles];
} else {
allArticles = dynamicArticles;
}
res.json({
data: {
curPage: page,
datas: allArticles,
offset: page * 20,
over: page >= 4,
pageCount: 5,
size: 20,
total: 50
},
errorCode: 0,
errorMsg: ""
});
});
// 项目分类API - https://www.wanandroid.com/project/tree/json
app.get('/api/project/tree/json', (req, res) => {
res.json({
data: [
{
children: [],
courseId: 13,
id: 294,
name: "完整项目",
order: 145000,
parentChapterId: 293,
visible: 1
},
{
children: [],
courseId: 13,
id: 402,
name: "跨平台应用",
order: 144000,
parentChapterId: 293,
visible: 1
},
{
children: [],
courseId: 13,
id: 367,
name: "资源聚合类",
order: 143000,
parentChapterId: 293,
visible: 1
},
{
children: [],
courseId: 13,
id: 323,
name: "动画",
order: 142000,
parentChapterId: 293,
visible: 1
},
{
children: [],
courseId: 13,
id: 314,
name: "RV列表动效",
order: 141000,
parentChapterId: 293,
visible: 1
},
{
children: [],
courseId: 13,
id: 358,
name: "项目基础功能",
order: 140000,
parentChapterId: 293,
visible: 1
},
{
children: [],
courseId: 13,
id: 296,
name: "网络&文件下载",
order: 139000,
parentChapterId: 293,
visible: 1
}
],
errorCode: 0,
errorMsg: ""
});
});
// 体系分类API - https://www.wanandroid.com/tree/json
app.get('/api/tree/json', (req, res) => {
res.json({
data: [
{
id: 1,
name: "开发环境",
order: 1000,
children: [
{ id: 11, name: "Android Studio相关", order: 1001 },
{ id: 12, name: "gradle", order: 1002 },
{ id: 13, name: "官方发布", order: 1003 },
{ id: 14, name: "90-120hz", order: 1004 }
]
},
{
id: 2,
name: "基础知识",
order: 2000,
children: [
{ id: 21, name: "Activity", order: 2001 },
{ id: 22, name: "Service", order: 2002 },
{ id: 23, name: "BroadcastReceiver", order: 2003 },
{ id: 24, name: "ContentProvider", order: 2004 }
]
},
{
id: 3,
name: "四大组件",
order: 3000,
children: [
{ id: 31, name: "Activity详解", order: 3001 },
{ id: 32, name: "Service详解", order: 3002 },
{ id: 33, name: "Broadcast详解", order: 3003 },
{ id: 34, name: "ContentProvider详解", order: 3004 }
]
},
{
id: 4,
name: "常用控件",
order: 4000,
children: [
{ id: 41, name: "TextView", order: 4001 },
{ id: 42, name: "Button", order: 4002 },
{ id: 43, name: "ImageView", order: 4003 },
{ id: 44, name: "RecyclerView", order: 4004 }
]
},
{
id: 5,
name: "UI/UX设计",
order: 5000,
children: [
{ id: 51, name: "Material Design", order: 5001 },
{ id: 52, name: "动画效果", order: 5002 },
{ id: 53, name: "响应式设计", order: 5003 },
{ id: 54, name: "用户体验", order: 5004 }
]
},
{
id: 6,
name: "网络编程",
order: 6000,
children: [
{ id: 61, name: "HTTP/HTTPS", order: 6001 },
{ id: 62, name: "Retrofit", order: 6002 },
{ id: 63, name: "OkHttp", order: 6003 },
{ id: 64, name: "WebSocket", order: 6004 }
]
},
{
id: 7,
name: "数据存储",
order: 7000,
children: [
{ id: 71, name: "SharedPreferences", order: 7001 },
{ id: 72, name: "SQLite", order: 7002 },
{ id: 73, name: "Room", order: 7003 },
{ id: 74, name: "文件存储", order: 7004 }
]
},
{
id: 8,
name: "性能优化",
order: 8000,
children: [
{ id: 81, name: "内存优化", order: 8001 },
{ id: 82, name: "启动优化", order: 8002 },
{ id: 83, name: "布局优化", order: 8003 },
{ id: 84, name: "网络优化", order: 8004 }
]
},
{
id: 9,
name: "架构设计",
order: 9000,
children: [
{ id: 91, name: "MVC/MVP/MVVM", order: 9001 },
{ id: 92, name: "组件化", order: 9002 },
{ id: 93, name: "模块化", order: 9003 },
{ id: 94, name: "Clean Architecture", order: 9004 }
]
},
{
id: 10,
name: "测试与调试",
order: 10000,
children: [
{ id: 101, name: "单元测试", order: 10001 },
{ id: 102, name: "UI测试", order: 10002 },
{ id: 103, name: "性能测试", order: 10003 },
{ id: 104, name: "调试技巧", order: 10004 }
]
}
],
errorCode: 0,
errorMsg: ""
});
});
// 项目列表API - https://www.wanandroid.com/project/list/1/json?cid=294
app.get('/api/project/list/:page/json', (req, res) => {
const page = parseInt(req.params.page) || 0;
const cid = parseInt(req.query.cid) || 294;
// 根据分类ID返回不同的项目数据
let projects = [];
if (cid === 294) { // 完整项目
projects = [
{
id: 101,
title: "玩Android Material Design客户端",
desc: "基于Uniapp框架开发的玩Android客户端,完全遵循Material Design 3设计规范",
author: "Material Design",
publishTime: Date.now() - 86400000,
zan: 42,
collect: false,
comments: 12,
fresh: true,
superChapterName: "完整项目"
},
{
id: 102,
title: "跨平台电商应用",
desc: "使用Uniapp开发的跨平台电商应用,支持iOS、Android、Web和小程序",
author: "Uniapp团队",
publishTime: Date.now() - 172800000,
zan: 28,
collect: true,
comments: 8,
fresh: false,
superChapterName: "完整项目"
}
];
} else if (cid === 402) { // 跨平台应用
projects = [
{
id: 201,
title: "智能家居控制中心",
desc: "基于Android的智能家居控制中心应用,支持多种智能设备连接和控制",
author: "IoT开发者",
publishTime: Date.now() - 259200000,
zan: 56,
collect: false,
comments: 24,
fresh: false,
superChapterName: "跨平台应用"
},
{
id: 202,
title: "在线教育平台",
desc: "完整的在线教育平台,包含课程管理、视频播放、在线测试、学习进度跟踪等功能",
author: "教育科技",
publishTime: Date.now() - 345600000,
zan: 89,
collect: true,
comments: 36,
fresh: false,
superChapterName: "跨平台应用"
}
];
} else if (cid === 367) { // 资源聚合类
projects = [
{
id: 301,
title: "技术文章聚合平台",
desc: "聚合各大技术网站的文章,提供统一的阅读体验和个性化推荐",
author: "技术聚合",
publishTime: Date.now() - 432000000,
zan: 34,
collect: false,
comments: 15,
fresh: true,
superChapterName: "资源聚合类"
}
];
} else {
// 默认项目数据
projects = [
{
id: 401,
title: "Material Design动画示例",
desc: "展示Material Design的各种动画效果和过渡",
author: "动画设计师",
publishTime: Date.now() - 518400000,
zan: 67,
collect: false,
comments: 28,
fresh: false,
superChapterName: "动画"
}
];
}
res.json({
data: {
curPage: page,
datas: projects,
offset: page * 20,
over: page >= 2,
pageCount: 3,
size: 20,
total: projects.length
},
errorCode: 0,
errorMsg: ""
});
});
// 用户信息API - https://www.wanandroid.com/user/lg/userinfo/json
app.get('/api/user/info/json', (req, res) => {
// 检查是否登录(通过请求头或cookie)
const authHeader = req.headers.authorization;
if (!authHeader) {
// 未登录状态
res.json({
errorCode: -1001,
errorMsg: "请先登录!",
data: null
});
return;
}
// 模拟已登录用户数据
res.json({
data: {
coinCount: 128,
collectIds: [1, 2, 3, 4, 5],
email: "caishushu@example.com",
icon: "",
id: 12345,
nickname: "蔡叔叔",
publicName: "蔡叔叔",
token: "",
type: 0,
username: "caishushu"
},
errorCode: 0,
errorMsg: ""
});
});
// 用户积分API - https://www.wanandroid.com/lg/coin/userinfo/json
app.get('/api/coin/userinfo/json', (req, res) => {
// 检查是否登录
const authHeader = req.headers.authorization;
if (!authHeader) {
res.json({
errorCode: -1001,
errorMsg: "请先登录!",
data: null
});
return;
}
// 模拟积分数据
res.json({
data: {
coinCount: 128,
level: 3,
rank: 156,
userId: 12345,
username: "caishushu"
},
errorCode: 0,
errorMsg: ""
});
});
// 收藏列表API - https://www.wanandroid.com/lg/collect/list/0/json
app.get('/api/collect/list/json', (req, res) => {
// 检查是否登录
const authHeader = req.headers.authorization;
if (!authHeader) {
res.json({
errorCode: -1001,
errorMsg: "请先登录!",
data: null
});
return;
}
// 模拟收藏数据
res.json({
data: {
curPage: 0,
datas: [
{
author: "Material Design",
chapterId: 1,
chapterName: "前端开发",
collect: true,
courseId: 13,
desc: "",
envelopePic: "",
fresh: false,
id: 1,
link: "https://www.wanandroid.com",
niceDate: "刚刚",
origin: "",
originId: -1,
publishTime: Date.now(),
title: "玩Android Material Design客户端发布",
userId: 12345,
visible: 1,
zan: 42
},
{
author: "Uniapp团队",
chapterId: 2,
chapterName: "Uniapp",
collect: true,
courseId: 13,
desc: "",
envelopePic: "",
fresh: false,
id: 2,
link: "https://uniapp.dcloud.io",
niceDate: "1小时前",
origin: "",
originId: -1,
publishTime: Date.now() - 3600000,
title: "Uniapp框架Material Design实践指南",
userId: 12345,
visible: 1,
zan: 28
}
],
offset: 0,
over: true,
pageCount: 1,
size: 20,
total: 2
},
errorCode: 0,
errorMsg: ""
});
});
// 分享列表API - https://www.wanandroid.com/user/2/share_articles/1/json
app.get('/api/share/list/json', (req, res) => {
// 检查是否登录
const authHeader = req.headers.authorization;
if (!authHeader) {
res.json({
errorCode: -1001,
errorMsg: "请先登录!",
data: null
});
return;
}
// 模拟分享数据
res.json({
data: {
curPage: 0,
datas: [
{
author: "蔡叔叔",
chapterId: 3,
chapterName: "Android开发",
collect: false,
courseId: 13,
desc: "分享一篇关于Material Design的文章",
envelopePic: "",
fresh: false,
id: 101,
link: "https://www.wanandroid.com",
niceDate: "1天前",
origin: "",
originId: -1,
publishTime: Date.now() - 86400000,
title: "Material Design在Android应用中的实践",
userId: 12345,
visible: 1,
zan: 15
},
{
author: "蔡叔叔",
chapterId: 4,
chapterName: "Uniapp",
collect: false,
courseId: 13,
desc: "分享Uniapp开发经验",
envelopePic: "",
fresh: false,
id: 102,
link: "https://uniapp.dcloud.io",
niceDate: "2天前",
origin: "",
originId: -1,
publishTime: Date.now() - 172800000,
title: "使用Uniapp开发跨平台应用的经验分享",
userId: 12345,
visible: 1,
zan: 8
}
],
offset: 0,
over: true,
pageCount: 1,
size: 20,
total: 2
},
errorCode: 0,
errorMsg: ""
});
});
// 登录API
app.post('/api/user/login/json', (req, res) => {
const { username, password } = req.body;
if (!username || !password) {
res.json({
errorCode: -1,
errorMsg: "用户名或密码不能为空",
data: null
});
return;
}
// 模拟登录成功
res.json({
data: {
admin: false,
chapterTops: [],
coinCount: 128,
collectIds: [],
email: username + "@example.com",
icon: "",
id: 12345,
nickname: username,
password: "",
publicName: username,
token: "mock_token_" + Date.now(),
type: 0,
username: username
},
errorCode: 0,
errorMsg: ""
});
});
// 退出登录API - https://www.wanandroid.com/user/logout/json
app.get('/api/user/logout/json', (req, res) => {
res.json({
data: null,
errorCode: 0,
errorMsg: ""
});
});
// 健康检查
app.get('/health', (req, res) => {
res.json({
status: 'healthy',
timestamp: new Date().toISOString(),
service: 'wanandroid-material-server',
version: '1.0.0',
uptime: process.uptime()
});
});
// 404处理
app.use((req, res) => {
res.status(404).send(`
<!DOCTYPE html>
<html>
<head>
<title>404 - 页面未找到</title>
<style>
body { font-family: 'Roboto', sans-serif; background: #F5F5F5; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
.error-container { text-align: center; padding: 40px; background: white; border-radius: 20px; box-shadow: 0 4px 20px rgba(0,0,0,0.1); }
.error-icon { font-size: 80px; color: #6200EE; margin-bottom: 24px; }
.error-title { font-size: 32px; font-weight: 500; color: #212121; margin-bottom: 16px; }
.error-message { font-size: 18px; color: #757575; margin-bottom: 32px; }
.error-path { font-family: 'Courier New', monospace; background: #F5F5F5; padding: 12px; border-radius: 8px; margin: 20px 0; }
.btn { display: inline-block; background: #6200EE; color: white; padding: 12px 24px; border-radius: 24px; text-decoration: none; margin-top: 20px; }
</style>
</head>
<body>
<div class="error-container">
<div class="error-icon">🔍</div>
<div class="error-title">404 - 页面未找到</div>
<div class="error-message">请求的页面不存在</div>
<div class="error-path">${req.originalUrl}</div>
<a href="/" class="btn">返回首页</a>
</div>
</body>
</html>
`);
});
// 启动服务器
app.listen(PORT, HOST, () => {
console.log(`
==============================================
玩Android Material Design开发服务器
==============================================
✅ 服务器启动成功!
📱 本地访问:
http://localhost:${PORT}
http://127.0.0.1:${PORT}
🌐 公网访问:
http://129.211.173.87:${PORT}
📁 项目信息:
项目路径: /home/ubuntu/wanandroid/uniapp_android
服务器IP: ${HOST}
服务端口: ${PORT}
Node版本: ${process.version}
🚀 可用路由:
/ - 首页预览
/index_correct.html - 正确首页(文章列表)
/projects.html - 项目页面
/profile.html - 我的页面
/material_preview.html - Material Design预览
/api/banner/json - Banner数据API
/api/hotkey/json - 搜索热词API
/api/article/list/:page/json - 文章列表API
/api/project/tree/json - 项目分类API
/api/project/list/:page/json - 项目列表API
/api/tree/json - 体系分类API
/api/user/info/json - 用户信息API
/api/coin/userinfo/json - 用户积分API
/api/collect/list/json - 收藏列表API
/api/share/list/json - 分享列表API
/health - 健康检查
⏰ 启动时间: ${new Date().toLocaleString()}
==============================================
`);
// 打印网络信息
const os = require('os');
const networkInterfaces = os.networkInterfaces();
console.log('📡 网络接口信息:');
Object.keys(networkInterfaces).forEach(interfaceName => {
networkInterfaces[interfaceName].forEach(interface => {
if (interface.family === 'IPv4' && !interface.internal) {
console.log(` ${interfaceName}: ${interface.address}`);
}
});
});
console.log('==============================================\n');
});
// 优雅关闭
process.on('SIGINT', () => {
console.log('\n🛑 收到关闭信号,正在停止服务器...');
process.exit(0);
});
process.on('SIGTERM', () => {
console.log('\n🛑 收到终止信号,正在停止服务器...');
process.exit(0);
});