Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CoCo_Code_Op2
Node Apollo
提交
f7df2c45
N
Node Apollo
项目概览
CoCo_Code_Op2
/
Node Apollo
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
Node Apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
f7df2c45
编写于
9月 22, 2017
作者:
Q
Quinton.Xu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test
上级
96b082ab
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
11 addition
and
9 deletion
+11
-9
README.md
README.md
+1
-1
lib/apollo.js
lib/apollo.js
+5
-4
package.json
package.json
+2
-1
test/index.js
test/index.js
+3
-3
未找到文件。
README.md
浏览文件 @
f7df2c45
...
...
@@ -5,7 +5,7 @@
## Install
```
bash
$
npm i node-apollo
--save-dev
--registry
=
http://http://116.62.161.40:7002
$
npm i node-apollo
--save-dev
```
## Usage
...
...
lib/apollo.js
浏览文件 @
f7df2c45
'
use strict
'
;
const
urllib
=
require
(
'
urllib
'
);
const
assert
=
require
(
'
assert
'
);
const
helper
=
require
(
'
./helper
'
);
module
.
exports
=
{
remoteConfigService
:
async
(
token
,
config
)
=>
{
remoteConfigService
:
async
(
config
)
=>
{
assert
(
config
,
'
param config is required
'
);
assert
(
config
.
token
,
'
param token is required
'
);
const
options
=
{
method
:
'
GET
'
,
headers
:
{
'
Content-Type
'
:
'
application/json;charset=UTF-8
'
,
authorization
:
token
,
authorization
:
config
.
token
,
},
rejectUnauthorized
:
false
,
contentType
:
'
json
'
,
dataType
:
'
json
'
,
};
const
res
=
await
urllib
.
request
(
helper
.
getAllConfigFromApolloUri
(
config
),
options
);
console
.
log
(
res
.
data
)
return
helper
.
mergeConfig
(
res
.
data
);
// ctx.app.config = 2
},
};
\ No newline at end of file
package.json
浏览文件 @
f7df2c45
{
"name"
:
"node-apollo"
,
"version"
:
"1.0.
0
"
,
"version"
:
"1.0.
3
"
,
"description"
:
"携程Apollo配置中心SDK。"
,
"main"
:
"index.js"
,
"scripts"
:
{
...
...
@@ -21,6 +21,7 @@
"
mocha
"
:
"
^3.5.3
"
},
"dependencies"
:
{
"
test
"
:
"
^1.0.0
"
,
"
urllib
"
:
"
^2.25.0
"
}
}
test/index.js
浏览文件 @
f7df2c45
...
...
@@ -6,14 +6,14 @@ const apollo = require('../index.js');
describe
(
'
#index
'
,
function
()
{
it
(
'
index.remoteConfigService
'
,
async
()
=>
{
const
config
=
{
configServerUrl
:
'
http://
116.62.161.40:8070
'
,
appId
:
'
gnetlink-cms-api
'
,
configServerUrl
:
'
http://
example.com
'
,
appId
:
'
<appId>
'
,
clusterName
:
'
default
'
,
namespaceName
:
''
,
apolloEnv
:
'
dev
'
,
// clientIp: '',
};
const
token
=
'
9037a4e8c14c3d61ac5dbbdfa379fc56f0e098ff
'
;
const
token
=
'
<apollo access token>
'
;
const
result
=
await
apollo
.
remoteConfigService
(
token
,
config
);
assert
(
Object
.
keys
(
result
).
length
>
0
,
'
Read config failed
'
);
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录