37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
import express, { json, urlencoded } from 'express';
|
|
import cors from 'cors';
|
|
import dotenv from 'dotenv';
|
|
import fileRouter from './upload/index.js';
|
|
import recordRouter from './outside/callback.js';
|
|
import mdWebSocketServer from './utils/mdWebSocketServer.js';
|
|
|
|
// 配置 dotenv 加载环境变量
|
|
dotenv.config();
|
|
|
|
const server = express(); // 接口url
|
|
const hostname = '0.0.0.0'; // IP地址
|
|
const port = process.env.CALLBACK_PORT || 8060; // 端口号
|
|
server.use(cors()); // 允许跨域
|
|
|
|
//设置静态资源路径
|
|
server.use('/workflow/uploads', express.static('uploads'));
|
|
|
|
// 添加 body-parser 中间件来解析 JSON 请求体
|
|
server.use(json());
|
|
server.use(urlencoded({ extended: true }));
|
|
|
|
server.use('/workflow/file', fileRouter);
|
|
server.use('/callback', recordRouter);
|
|
|
|
// 启动服务器
|
|
server.listen(port, hostname, () => {
|
|
console.log(`Server running at http://${hostname}:${port}/`);
|
|
|
|
// 初始化 WebSocket 服务
|
|
mdWebSocketServer.init().then(() => {
|
|
console.log('[MDWebSocketServer] 初始化完成');
|
|
}).catch((error) => {
|
|
console.error('[MDWebSocketServer] 初始化失败:', error);
|
|
});
|
|
});
|