Guanghu Domestic Migration d1e47f4565
Some checks are pending
自动更新代码和重启 / update-and-restart (push) Waiting to run
CI检查 + 自动部署 / check (push) Waiting to run
CI检查 + 自动部署 / deploy (push) Blocked by required conditions
重启聊天服务 / restart (push) Waiting to run
chore: import sanitized domestic snapshot for REPO-002
Source snapshot: ca48d3ddf926d79aa138306164169baf764bb829
2026-07-17 15:54:41 +08:00

69 lines
2.6 KiB
JavaScript

/**
* 光湖短视频工作台 · API Server
* Express + Socket.IO
*
* 霜砚出品 · AG-SY-WEB-001
*/
const express = require('express');
const http = require('http');
const { Server } = require('socket.io');
const cors = require('cors');
const path = require('path');
const config = require('./config');
const app = express();
const server = http.createServer(app);
// ── CORS ────────────────────────────────────────────
app.use(cors({ origin: config.corsOrigins, credentials: true }));
app.use(express.json({ limit: '1mb' }));
// ── Socket.IO ───────────────────────────────────────
const io = new Server(server, {
cors: { origin: config.corsOrigins, credentials: true },
pingTimeout: 60000,
});
app.set('io', io);
// ── 静态文件 (生产环境) ──────────────────────────────
const distPath = path.resolve(__dirname, '../frontend/dist');
app.use(express.static(distPath));
// ── API 路由 ────────────────────────────────────────
app.use('/api/video', require('./routes/video'));
// 健康检查
app.get('/api/health', (_req, res) => {
res.json({
status: 'ok',
service: 'guanghuclip-api',
version: '1.0.0-p0',
timestamp: new Date().toISOString(),
jimengConfigured: !!config.jimeng.apiKey,
});
});
// ── SPA 回退 (生产环境) ─────────────────────────────
app.get('*', (_req, res) => {
res.sendFile(path.join(distPath, 'index.html'));
});
// ── Socket.IO 事件 ──────────────────────────────────
io.on('connection', (socket) => {
console.log(`[Socket] 连接: ${socket.id}`);
socket.on('disconnect', () => {
console.log(`[Socket] 断开: ${socket.id}`);
});
});
// ── 启动 ────────────────────────────────────────────
server.listen(config.port, () => {
console.log('');
console.log(' 🎬 光湖短视频工作台 API');
console.log(` ── 端口: ${config.port}`);
console.log(` ── 时间: ${new Date().toISOString()}`);
console.log(` ── 即梦: ${config.jimeng.apiKey ? '✅ 已配置' : '❌ 未配置'}`);
console.log(` ── 模型: ${config.jimeng.model}`);
console.log('');
});