const express = require('express'); // Express框架,用于创建Web服务器
const fs = require('fs'); // 同步文件系统模块
const path = require('path'); // 路径模块,用于处理文件路径
const https = require("https"); // HTTPS模块,用于创建HTTPS服务器
// 创建Express应用实例
const app = express();
// 定义服务器端口
const port = 3480;
// HTTPS证书配置
const https_option = {
key: fs.readFileSync("./ssl/www.u3d.ltd.key"), // 读取私钥文件
cert: fs.readFileSync("./ssl/www.u3d.ltd.crt") // 读取证书文件
}
// 创建HTTPS服务器
const server = https.createServer(https_option, app);
// 提供 Android 目录下的静态文件
app.use('/Android', express.static(path.join(__dirname, '/hotfix/Android')));
// 全局错误处理中间件
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).json({ message: 'Internal Server Error' });
});
// 启动服务器并监听指定端口
server.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});
环境
centos7
宝塔 pm2
nodejs
ssl证书