cmvr-wms/mobile-app/metro.config.js
lixiaolong cd86623061 feat(app): 添加服务器连接管理和到货操作功能
- 集成 ServerConnection 组件用于开发环境服务器切换
- 实现多服务器令牌隔离存储机制
- 添加 ArrivalOperation 屏幕处理到货和验收流程
- 支持待登记到货和待验收状态切换
- 优化库存操作界面的字段显示逻辑
- 增强 Excel 文件分片上传支持产品文件识别
- 添加 AI 助手会话滚动跟踪功能
- 实现开发服务器地址持久化存储
- 优化登录界面集成服务器连接组件
- 添加领用出库功能支持项目物资使用
- 改进盘点确认生效的操作流程
- 增强采购到货登记和验收的权限控制
- 优化移动端文件上传的断点续传机制
- 添加服务器切换时的数据清理保护机制
- 实现紧凑金额显示模式减少界面冗余
- 增强库存操作的数量验证和错误提示
- 优化 AI 助手的会话状态同步机制
2026-10-20 10:04:17 +08:00

33 lines
2.1 KiB
JavaScript

const { getDefaultConfig } = require('expo/metro-config');
const http = require('node:http');
const https = require('node:https');
const { environment, internal } = require('./config/environment.cjs');
const config = getDefaultConfig(__dirname);
// Never crawl or bundle signing credentials, including access-restricted folders.
const previousBlocks=config.resolver.blockList;
config.resolver.blockList=[...(Array.isArray(previousBlocks)?previousBlocks:previousBlocks?[previousBlocks]:[]),/[\\/]keys(?:[\\/]|$)/,/[\\/]ota-data(?:[\\/]|$)/];
// Web is a developer preview only. A same-origin proxy avoids preview-browser
// private-network/CORS restrictions; installed Android calls the API directly.
config.server = { ...config.server, enhanceMiddleware: middleware => (req, res, next) => {
if (!req.url.startsWith('/native-api/')) return middleware(req, res, next);
const env = environment();
const suffix = req.url.slice('/native-api'.length);
if (suffix.includes('://') || suffix.includes('..')) { res.writeHead(400); res.end(); return; }
let apiUrl=env.apiUrl;
const selected=req.headers['x-cmvr-dev-server'];
if(selected){
try{if(env.variant!=='dev'||typeof selected!=='string'||selected.length>240)throw Error('invalid target');apiUrl=internal(selected,true);}
catch{res.writeHead(400,{'Content-Type':'application/json'});res.end(JSON.stringify({code:400,msg:'请填写有效的开发内网服务地址。'}));return;}
}
const target = new URL(apiUrl + suffix);
const headers={...req.headers,host:target.host};delete headers['x-cmvr-dev-server'];
const transport = target.protocol === 'https:' ? https : http;
const upstream = transport.request(target, { method:req.method, headers,timeout:220000 }, response => {
res.writeHead(response.statusCode, response.headers); response.pipe(res);
});
upstream.on('timeout',()=>upstream.destroy());
upstream.on('error',()=>{if(!res.headersSent)res.writeHead(502,{'Content-Type':'application/json'});res.end(JSON.stringify({code:502,msg:'开发预览暂未连接后端。'}));});
req.pipe(upstream);
}};
module.exports = config;