#!/usr/bin/env node /** * 本地转发代理:当手机无法直连 pre-ai.petsheroai.xyz 时使用 * 电脑能访问域名,手机连电脑同一 WiFi,通过此代理转发请求 * * 使用: * 1. 手机和电脑连同一 WiFi * 2. 运行: node scripts/dev_proxy.js * 3. 在 api_config.dart 中设置 debugBaseUrlOverride = 'http://<电脑IP>:8010' * 4. 手机运行 app * * 获取电脑 IP: ifconfig (Mac/Linux) 或 ipconfig (Windows) */ const http = require('http'); const https = require('https'); const TARGET = 'https://pre-ai.petsheroai.xyz'; const PORT = 8010; const server = http.createServer((req, res) => { const url = TARGET + req.url; console.log(`[${new Date().toISOString()}] ${req.method} ${req.url} -> ${url}`); const options = { hostname: 'pre-ai.petsheroai.xyz', port: 443, path: req.url, method: req.method, headers: { ...req.headers, host: 'pre-ai.petsheroai.xyz' }, }; const proxy = https.request(options, (proxyRes) => { res.writeHead(proxyRes.statusCode, proxyRes.headers); proxyRes.pipe(res); }); proxy.on('error', (e) => { console.error('Proxy error:', e.message); res.writeHead(502); res.end('Proxy error: ' + e.message); }); req.pipe(proxy); }); server.listen(PORT, '0.0.0.0', () => { console.log(`Dev proxy listening on http://0.0.0.0:${PORT}`); console.log(`Forwarding to ${TARGET}`); console.log('Set debugBaseUrlOverride = "http://:8010" in api_config.dart'); });