Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ethan
/
appframe
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 3c9b96b2
authored
2025-12-11 17:20:34 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
启用本机服务时,支持多端口备用
1 parent
8d27884d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
11 deletions
lib/config/constant.dart
lib/services/local_server_service.dart
lib/config/constant.dart
View file @
3c9b96b
...
@@ -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 相关
/// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...
@@ -28,7 +30,8 @@ class Constant {
...
@@ -28,7 +30,8 @@ class Constant {
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
=
[
'homework'
,
'clockin'
,
'clockin'
,
'clock'
,
'clock'
,
'clazzclock'
,
'clazzclock'
,
...
@@ -40,13 +43,14 @@ class Constant {
...
@@ -40,13 +43,14 @@ class Constant {
'txbb'
,
'txbb'
,
'dictation'
,
'dictation'
,
'xegd'
,
'xegd'
,
'kouyu'
];
'kouyu'
];
/// 版本相关
/// 版本相关
/// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///
///
/// app 版本号规则
/// app 版本号规则
static
const
String
appVersion
=
'1.0.251211
2
'
;
static
const
String
appVersion
=
'1.0.251211
4
'
;
/// 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 相关
/// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///
///
...
...
lib/services/local_server_service.dart
View file @
3c9b96b
...
@@ -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
;
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}
'
);
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
;
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment