更新一下

This commit is contained in:
2025-09-21 00:31:55 +08:00
parent 55b0e47171
commit d02086dee5
7 changed files with 4632 additions and 170 deletions

1
.htaccess Normal file
View File

@@ -0,0 +1 @@
# 请将伪静态规则或自定义Apache配置填写到此处

View File

@@ -1,77 +0,0 @@
// 宝塔环境下的Node项目启动脚本
import { spawn } from 'child_process';
import path from 'path';
import fs from 'fs';
import { fileURLToPath } from 'url';
// 获取当前文件的目录路径
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// 获取项目根目录
const rootDir = __dirname;
const serverPath = path.join(rootDir, 'server', 'index.js');
// 检查日志目录
const logDir = path.join(rootDir, 'logs');
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir, { recursive: true });
}
// 创建日志文件流
const logFile = path.join(logDir, 'server.log');
const logStream = fs.createWriteStream(logFile, { flags: 'a' });
console.log('启动后端服务器...');
console.log(`日志文件: ${logFile}`);
// 创建前端构建目录
const distDir = path.join(rootDir, 'server', 'dist');
if (!fs.existsSync(distDir)) {
console.log(`创建前端构建目录: ${distDir}`);
fs.mkdirSync(distDir, { recursive: true });
// 如果dist目录不存在尝试从dist目录复制
const srcDistDir = path.join(rootDir, 'dist');
if (fs.existsSync(srcDistDir)) {
console.log(`${srcDistDir} 复制前端文件到 ${distDir}`);
fs.cpSync(srcDistDir, distDir, { recursive: true });
} else {
console.log('警告: 前端构建文件不存在,请先运行 npm run build');
// 创建一个临时index.html避免服务器报错
fs.writeFileSync(path.join(distDir, 'index.html'), '<html><body><h1>抽奖系统</h1><p>前端文件未构建,请先运行 npm run build</p></body></html>');
}
}
// 使用start:node server.js启动服务器
const server = spawn('node', ['server/index.js'], {
cwd: rootDir,
env: {
...process.env,
PORT: 3010,
NODE_ENV: 'production'
},
stdio: ['ignore', 'pipe', 'pipe']
});
console.log('使用启动命令: start:node server.js');
// 将输出写入日志
server.stdout.pipe(logStream);
server.stderr.pipe(logStream);
server.stdout.on('data', (data) => {
console.log(`[服务器输出] ${data.toString().trim()}`);
});
server.stderr.on('data', (data) => {
console.error(`[服务器错误] ${data.toString().trim()}`);
});
server.on('close', (code) => {
console.log(`服务器进程退出,退出码: ${code}`);
logStream.end();
});
console.log(`后端服务已启动,端口: 3010`);
console.log('使用 pm2 或 forever 保持此脚本运行');

13
package-lock.json generated
View File

@@ -46,7 +46,6 @@
"typescript": "~5.8.3", "typescript": "~5.8.3",
"typescript-eslint": "^8.30.1", "typescript-eslint": "^8.30.1",
"vite": "^6.3.5", "vite": "^6.3.5",
"vite-plugin-trae-solo-badge": "^1.0.0",
"vite-tsconfig-paths": "^5.1.4" "vite-tsconfig-paths": "^5.1.4"
} }
}, },
@@ -7389,18 +7388,6 @@
} }
} }
}, },
"node_modules/vite-plugin-trae-solo-badge": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/vite-plugin-trae-solo-badge/-/vite-plugin-trae-solo-badge-1.0.0.tgz",
"integrity": "sha512-vrNr4QmbcqqMeJPzHBqef70nqDzN6CQngFwuXTJMAgn3zMU4TWzvY0B3BRdjUjvg/BtvNJLlwu2cPKXTUjalHg==",
"dev": true,
"dependencies": {
"tslib": "^2.8.1"
},
"peerDependencies": {
"vite": ">=4.0.0"
}
},
"node_modules/vite-tsconfig-paths": { "node_modules/vite-tsconfig-paths": {
"version": "5.1.4", "version": "5.1.4",
"resolved": "https://registry.npmjs.org/vite-tsconfig-paths/-/vite-tsconfig-paths-5.1.4.tgz", "resolved": "https://registry.npmjs.org/vite-tsconfig-paths/-/vite-tsconfig-paths-5.1.4.tgz",

4631
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,46 +0,0 @@
// 重置所有密码为123456的脚本
const sqlite3 = require('sqlite3').verbose();
const path = require('path');
const fs = require('fs');
// 获取项目根目录
const rootDir = __dirname;
const dbPath = path.join(rootDir, 'server', 'lottery.db');
console.log('开始重置所有密码为123456...');
console.log(`数据库路径: ${dbPath}`);
// 检查数据库文件是否存在
if (!fs.existsSync(dbPath)) {
console.error(`错误: 数据库文件不存在: ${dbPath}`);
process.exit(1);
}
// 连接数据库
const db = new sqlite3.Database(dbPath, (err) => {
if (err) {
console.error(`连接数据库失败: ${err.message}`);
process.exit(1);
}
console.log('成功连接到数据库');
// 更新系统配置表中的密码
db.run(
`UPDATE system_config SET admin_password = '123456', login_password = '123456'`,
function(err) {
if (err) {
console.error(`更新密码失败: ${err.message}`);
db.close();
process.exit(1);
}
console.log(`密码更新成功! 已修改 ${this.changes} 条记录`);
console.log('所有密码已重置为: 123456');
// 关闭数据库连接
db.close(() => {
console.log('数据库连接已关闭');
});
}
);
});

Binary file not shown.

View File

@@ -1,34 +0,0 @@
#!/bin/bash
# 抽奖系统启动脚本
echo "正在启动抽奖系统..."
# 检查依赖是否安装
if [ ! -d "node_modules" ]; then
echo "正在安装依赖..."
npm install
fi
# 启动后端服务器
echo "启动后端服务器 (端口 3010)..."
node server/index.js &
BACKEND_PID=$!
# 等待后端启动
sleep 3
# 启动前端开发服务器
echo "启动前端开发服务器 (端口 5173)..."
npm run dev &
FRONTEND_PID=$!
echo "系统启动完成!"
echo "前端地址: http://localhost:5173"
echo "后端API: http://localhost:3010"
echo "按 Ctrl+C 停止所有服务"
# 捕获退出信号,清理进程
trap 'echo "正在停止服务..."; kill $BACKEND_PID $FRONTEND_PID; exit' INT TERM
# 等待进程结束
wait