Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nodejs-yitong-sdk
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Metrics
Environments
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
yitong-public
nodejs-yitong-sdk
Commits
e504d2f8
Commit
e504d2f8
authored
Mar 05, 2025
by
肖人杰
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git-ssh.devops.yitong.com:yitong-public/nodejs-yitong-sdk
parents
8486d785
ce061846
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
14 deletions
+44
-14
package.json
package.json
+1
-1
yitong-sdk.js
yitong-sdk.js
+43
-13
No files found.
package.json
View file @
e504d2f8
{
"name"
:
"nodejs-yitong-sdk"
,
"version"
:
"1.0.
5
"
,
"version"
:
"1.0.
7
"
,
"description"
:
""
,
"main"
:
"index.js"
,
"scripts"
:
{
...
...
yitong-sdk.js
View file @
e504d2f8
...
...
@@ -28,8 +28,6 @@ class ApiError extends Error {
}
}
/**
* YiTong SDK HTTP
*/
...
...
@@ -43,19 +41,42 @@ const http = axios.create({
httpAgent
:
new
require
(
'
http
'
).
Agent
({
keepAlive
:
true
}),
httpsAgent
:
new
require
(
'
https
'
).
Agent
({
keepAlive
:
true
})
});
// koa opentracing
// https://github.com/fapspirit/axios-opentracing
http
.
interceptors
.
request
.
use
(
function
(
config
)
{
if
(
global
.
serviceMap
)
{
let
paths
=
config
.
url
.
split
(
"
/
"
)
if
(
paths
.
length
>=
4
){
let
pathKey
=
paths
[
0
]
+
"
//
"
+
paths
[
2
]
+
"
/
"
+
paths
[
3
]
+
"
/
"
if
(
global
.
serviceMap
[
pathKey
])
{
config
.
url
=
config
.
url
.
replace
(
pathKey
,
global
.
serviceMap
[
pathKey
])
// URL转换 域名 转 k8s serviceName
if
(
process
.
env
.
YT_SERVICE_RULES
)
{
const
{
serviceRuleMap
}
=
require
(
process
.
env
.
YT_SERVICE_RULES
);
if
(
_
.
size
(
serviceRuleMap
)
>
0
)
{
let
rules
=
new
Map
();
for
(
const
key
of
Object
.
keys
(
serviceRuleMap
))
{
const
value
=
serviceRuleMap
[
key
];
rules
.
set
(
key
,
value
);
if
(
key
.
startsWith
(
"
http://
"
))
{
rules
.
set
(
`https://
${
key
.
substring
(
7
)}
`
,
value
);
}
}
let
rulesCache
=
new
Map
();
http
.
interceptors
.
request
.
use
(
function
(
config
)
{
let
url
=
config
.
url
;
if
(
url
)
{
let
newUrl
=
rulesCache
.
get
(
config
.
url
);
if
(
!
newUrl
)
{
for
(
const
[
key
,
value
]
of
rules
)
{
if
(
url
.
startsWith
(
key
))
{
newUrl
=
`
${
value
}${
url
.
substring
(
key
.
length
)}
`
rulesCache
.
set
(
url
,
newUrl
)
}
}
}
if
(
newUrl
)
{
config
.
url
=
newUrl
;
}
}
return
config
;
});
}
}
// koa opentracing
// https://github.com/fapspirit/axios-opentracing
http
.
interceptors
.
request
.
use
(
function
(
config
)
{
if
(
config
.
context
&&
config
.
context
.
span
)
{
let
tracer
=
opentracing
.
globalTracer
();
let
span
=
tracer
.
startSpan
(
`
${
config
.
method
}
:
${
config
.
url
}
`
,
{
...
...
@@ -188,7 +209,16 @@ function errorHandler() {
}
catch
(
e
)
{
ctx
.
status
=
200
;
ctx
.
body
=
transformError
(
e
);
log
.
error
(
e
);
log
.
error
({
url
:
ctx
.
request
.
url
,
body
:
ctx
.
request
.
body
,
headers
:
{
"
user-agent
"
:
ctx
.
headers
[
"
user-agent
"
],
"
x-real-ip
"
:
ctx
.
headers
[
"
x-real-ip
"
],
"
x-forwarded-for
"
:
ctx
.
headers
[
"
x-forwarded-for
"
]
},
error
:
e
});
}
};
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment