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
794efb5d
Commit
794efb5d
authored
Mar 28, 2020
by
huhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
配置文件外移
parent
f9da1759
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
21 deletions
+18
-21
yitong-sdk.js
yitong-sdk.js
+18
-21
No files found.
yitong-sdk.js
View file @
794efb5d
...
@@ -9,9 +9,6 @@ const jaeger = require('jaeger-client');
...
@@ -9,9 +9,6 @@ const jaeger = require('jaeger-client');
const
log
=
require
(
'
log4js
'
).
getLogger
();
const
log
=
require
(
'
log4js
'
).
getLogger
();
const
httpLog
=
require
(
'
log4js
'
).
getLogger
(
'
http
'
);
const
httpLog
=
require
(
'
log4js
'
).
getLogger
(
'
http
'
);
// 配置文件
const
props
=
require
(
'
./props.json
'
);
/**
/**
* 业务异常
* 业务异常
*/
*/
...
@@ -199,8 +196,8 @@ function debug() {
...
@@ -199,8 +196,8 @@ function debug() {
* opentracing链路跟踪中间件
* opentracing链路跟踪中间件
* https://github.com/opentracing-contrib/javascript-express
* https://github.com/opentracing-contrib/javascript-express
*/
*/
function
tracing
()
{
function
tracing
(
opts
)
{
opentracing
.
initGlobalTracer
(
jaeger
.
initTracer
(
prop
s
.
tracing
));
opentracing
.
initGlobalTracer
(
jaeger
.
initTracer
(
opt
s
.
tracing
));
const
tracer
=
opentracing
.
globalTracer
();
const
tracer
=
opentracing
.
globalTracer
();
return
async
function
(
ctx
,
next
)
{
return
async
function
(
ctx
,
next
)
{
let
wireCtx
=
tracer
.
extract
(
opentracing
.
FORMAT_HTTP_HEADERS
,
ctx
.
headers
);
let
wireCtx
=
tracer
.
extract
(
opentracing
.
FORMAT_HTTP_HEADERS
,
ctx
.
headers
);
...
@@ -295,9 +292,9 @@ function headerx() {
...
@@ -295,9 +292,9 @@ function headerx() {
/**
/**
* Token解析中间件
* Token解析中间件
*/
*/
function
token
()
{
function
token
(
opts
)
{
// token公钥,缓存
// token公钥,缓存
const
publicKey
=
axios
(
`
${
prop
s
.
apiBase
}
/auth/oauth2/public-key.pem`
);
const
publicKey
=
axios
(
`
${
opt
s
.
apiBase
}
/auth/oauth2/public-key.pem`
);
return
async
function
(
ctx
,
next
)
{
return
async
function
(
ctx
,
next
)
{
let
authorizationToken
=
ctx
.
getAuthorizationToken
();
let
authorizationToken
=
ctx
.
getAuthorizationToken
();
if
(
authorizationToken
)
{
if
(
authorizationToken
)
{
...
@@ -337,7 +334,7 @@ function token() {
...
@@ -337,7 +334,7 @@ function token() {
/**
/**
* 鉴权中间件
* 鉴权中间件
*/
*/
function
auth
()
{
function
auth
(
opts
)
{
return
async
function
(
ctx
,
next
)
{
return
async
function
(
ctx
,
next
)
{
/**
/**
* 当前用户
* 当前用户
...
@@ -346,7 +343,7 @@ function auth() {
...
@@ -346,7 +343,7 @@ function auth() {
if
(
ctx
.
token
)
{
if
(
ctx
.
token
)
{
return
http
({
return
http
({
context
:
ctx
,
context
:
ctx
,
url
:
`
${
prop
s
.
apiBase
}
/auth/v3/user/getUser`
,
url
:
`
${
opt
s
.
apiBase
}
/auth/v3/user/getUser`
,
data
:
{
data
:
{
appKey
:
ctx
.
getAppKey
()
appKey
:
ctx
.
getAppKey
()
}
}
...
@@ -361,10 +358,10 @@ function auth() {
...
@@ -361,10 +358,10 @@ function auth() {
ctx
.
getApplicationToken
=
function
()
{
ctx
.
getApplicationToken
=
function
()
{
return
http
({
return
http
({
context
:
ctx
,
context
:
ctx
,
url
:
`
${
prop
s
.
apiBase
}
/auth/v3/application/getTokenByApplication`
,
url
:
`
${
opt
s
.
apiBase
}
/auth/v3/application/getTokenByApplication`
,
data
:
{
data
:
{
appKey
:
prop
s
.
appKey
,
appKey
:
opt
s
.
appKey
,
appSecret
:
prop
s
.
appSecret
appSecret
:
opt
s
.
appSecret
}
}
});
});
};
};
...
@@ -375,12 +372,12 @@ function auth() {
...
@@ -375,12 +372,12 @@ function auth() {
/**
/**
* 用户行为跟踪上报中间件
* 用户行为跟踪上报中间件
*/
*/
function
track
()
{
function
track
(
opts
)
{
return
async
function
(
ctx
,
next
)
{
return
async
function
(
ctx
,
next
)
{
ctx
.
track
=
true
;
// 全部接口收集
ctx
.
track
=
true
;
// 全部接口收集
ctx
.
trackEvent
=
{
ctx
.
trackEvent
=
{
__referer__
:
`
${
prop
s
.
serviceName
}
:
${
ctx
.
path
}
`
,
__referer__
:
`
${
opt
s
.
serviceName
}
:
${
ctx
.
path
}
`
,
app_key
:
ctx
.
getAppKey
()
||
_
.
get
(
ctx
.
token
,
'
aud
'
)
||
prop
s
.
appKey
,
app_key
:
ctx
.
getAppKey
()
||
_
.
get
(
ctx
.
token
,
'
aud
'
)
||
opt
s
.
appKey
,
event
:
{
event
:
{
key
:
'
api
'
key
:
'
api
'
},
},
...
@@ -407,7 +404,7 @@ function track() {
...
@@ -407,7 +404,7 @@ function track() {
}).
join
(
'
&
'
);
}).
join
(
'
&
'
);
axios
({
axios
({
method
:
'
GET
'
,
method
:
'
GET
'
,
url
:
`
${
prop
s
.
trackBase
}${
trackQuery
}
`
,
url
:
`
${
opt
s
.
trackBase
}${
trackQuery
}
`
,
headers
:
{
headers
:
{
'
user-agent
'
:
ctx
.
headers
[
'
user-agent
'
]
'
user-agent
'
:
ctx
.
headers
[
'
user-agent
'
]
}
}
...
@@ -451,14 +448,14 @@ function notEmpty(value, message) {
...
@@ -451,14 +448,14 @@ function notEmpty(value, message) {
/**
/**
* App扩展
* App扩展
*/
*/
function
extendApp
(
app
)
{
function
extendApp
(
app
,
opts
)
{
app
.
use
(
errorHandler
());
// 启用异常处理
app
.
use
(
errorHandler
());
// 启用异常处理
app
.
use
(
debug
());
// 启用请求参数调试
app
.
use
(
debug
());
// 启用请求参数调试
app
.
use
(
tracing
());
// 启用链路跟踪
app
.
use
(
tracing
(
opts
));
// 启用链路跟踪
app
.
use
(
headerx
());
// 启用亿童请求头提取
app
.
use
(
headerx
());
// 启用亿童请求头提取
app
.
use
(
token
());
// 启动token解析
app
.
use
(
token
(
opts
));
// 启动token解析
app
.
use
(
auth
());
// 启动鉴权中间件
app
.
use
(
auth
(
opts
));
// 启动鉴权中间件
app
.
use
(
track
());
// 启动用户行为跟踪
app
.
use
(
track
(
opts
));
// 启动用户行为跟踪
return
app
;
return
app
;
}
}
...
...
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