You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

const { app, BrowserWindow } = require("electron");
const path = require("path");
const http = require("http");
const httpProxy = require("http-proxy"); // 需要安装npm install http-proxy
// 创建代理服务器
const proxyServer = httpProxy.createProxyServer({});
// 定义目标服务
const proxyTargets = {
"/live-digital-avatar-manage": "http://192.168.10.25:8080/live-digital-avatar-manage",
"/asr": "http://192.168.10.138:8090",
"/tts": "http://192.168.10.113:9880"
};
// 创建本地 HTTP 服务器
const server = http.createServer((req, res) => {
// 根据请求路径匹配目标服务
for (const pathPrefix in proxyTargets) {
if (req.url.startsWith(pathPrefix)) {
const target = proxyTargets[pathPrefix];
// 重写路径(移除前缀)
req.url = req.url.replace(pathPrefix, "");
// 转发请求
proxyServer.web(req, res, { target });
return;
}
}
res.statusCode = 404;
res.end("Not Found");
});
// 启动服务器
server.listen(3000, () => {
console.log("Proxy server running on port 3000");
});
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, "preload.js"), // 使用计算后的 __dirname
nodeIntegration: true,
contextIsolation: false
}
});
// 加载应用
win.loadFile("dist/index.html");
}
app.whenReady().then(createWindow);