Commit 3c9b96b2 by tanghuan

启用本机服务时,支持多端口备用

1 parent 8d27884d
...@@ -5,18 +5,20 @@ class Constant { ...@@ -5,18 +5,20 @@ class Constant {
/// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// ///
/// 应用内部 http 服务 /// 应用内部 http 服务
static const int localServerPort = 35982; ///
// static const String localServerHost = 'appdev-xj.banxiaoer.net'; // static const String localServerHost = 'appdev-xj.banxiaoer.net';
static const String localServerHost = '127.0.0.1'; static const String localServerHost = '127.0.0.1';
static const String localServerUrl = 'http://$localServerHost:$localServerPort'; static int localServerPort = 35982;
static const localServerPortOption = [35982, 35983, 35984];
static const String localFileUrl = 'http://127.0.0.1:$localServerPort'; static final String localServerUrl = 'http://$localServerHost:$localServerPort';
static final String localFileUrl = 'http://127.0.0.1:$localServerPort';
static const String localServerTemp = '/temp'; static const String localServerTemp = '/temp';
static const String localServerTempFileUrl = '$localFileUrl$localServerTemp'; static final String localServerTempFileUrl = '$localFileUrl$localServerTemp';
static const String localServerTest = '/test'; static const String localServerTest = '/test';
static const String localServerTestFileUrl = '$localFileUrl$localServerTest'; static final String localServerTestFileUrl = '$localFileUrl$localServerTest';
/// obs 相关 /// obs 相关
/// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -27,26 +29,28 @@ class Constant { ...@@ -27,26 +29,28 @@ class Constant {
/// obs文件上传的逻辑前缀 /// obs文件上传的逻辑前缀
static const String obsLogicPrefix = EnvConfig.env == 'dev' ? 'd2/pridel/user/' : 'p2/unpridel/user/'; static const String obsLogicPrefix = EnvConfig.env == 'dev' ? 'd2/pridel/user/' : 'p2/unpridel/user/';
// 定义obs存储业务上的关键业务类型,属于这种类型的业务,在存储上区分其分属于何种删除规则 // 定义obs存储业务上的关键业务类型,属于这种类型的业务,在存储上区分其分属于何种删除规则
static const List<String> obsPridelFileConfigs = ['homework', static const List<String> obsPridelFileConfigs = [
'clockin', 'homework',
'clock', 'clockin',
'clazzclock', 'clock',
'clockinQcard', 'clazzclock',
'recite', 'clockinQcard',
'aloud', 'recite',
'hurdle', 'aloud',
'tbx', 'hurdle',
'txbb', 'tbx',
'dictation', 'txbb',
'xegd', 'dictation',
'kouyu']; 'xegd',
'kouyu'
];
/// 版本相关 /// 版本相关
/// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// ///
/// app 版本号规则 /// app 版本号规则
static const String appVersion = '1.0.2512112'; static const String appVersion = '1.0.2512114';
/// H5的起始终最低版本号规则 /// H5的起始终最低版本号规则
static const String h5Version = '1.0.0'; static const String h5Version = '1.0.0';
...@@ -79,7 +83,6 @@ class Constant { ...@@ -79,7 +83,6 @@ class Constant {
static const String wxAppId = 'wx8c32ea248f0c7765'; static const String wxAppId = 'wx8c32ea248f0c7765';
static const String universalLink = 'https://dev.banxiaoer.net/path/to/wechat/'; static const String universalLink = 'https://dev.banxiaoer.net/path/to/wechat/';
/// IM 相关 /// IM 相关
/// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// ///
......
...@@ -16,8 +16,21 @@ class LocalServerService { ...@@ -16,8 +16,21 @@ class LocalServerService {
// 测试情况下, 每次启动服务,先解压dist文件 // 测试情况下, 每次启动服务,先解压dist文件
await _extractDist(); await _extractDist();
HttpServer server = await HttpServer.bind(InternetAddress.loopbackIPv4, Constant.localServerPort); late HttpServer server;
print('本地服务器启动在端口: ${server.port}'); int maxRetries = Constant.localServerPortOption.length;
for (int i = 0; i < maxRetries; i++) {
try {
server = await HttpServer.bind(InternetAddress.loopbackIPv4, Constant.localServerPortOption[i]);
Constant.localServerPort = server.port;
print('本地服务器启动在端口: ${server.port}');
break;
} on SocketException catch (e) {
print('端口 ${Constant.localServerPortOption[i]} 被占用,尝试下一个端口...');
if (i == maxRetries - 1) {
throw Exception('端口全部被占用,本地服务启动失败');
}
}
}
server.listen((HttpRequest request) async { server.listen((HttpRequest request) async {
final String requestPath = request.uri.path == '/' ? '/index.html' : request.uri.path; final String requestPath = request.uri.path == '/' ? '/index.html' : request.uri.path;
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!