Skip to content
This repository has been archived by the owner on May 7, 2022. It is now read-only.

Commit

Permalink
fix: #2
Browse files Browse the repository at this point in the history
  • Loading branch information
xuexb committed May 2, 2018
1 parent f2ec38c commit bf99a24
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ export default class MipCache {
* @return {Promise}
*/
clear(url) {
url = this._parseUrl(url);
const domain = this._parseUrl(url);
const api = url.indexOf('https://') === 0
? 'http://c.mipcdn.com/update-ping/c/s'
: 'http://c.mipcdn.com/update-ping/c';

return new Promise((resolve, reject) => {
request.post(`http://mipcache.bdstatic.com/update-ping/c/${url}`, {
request.post(`${api}/${domain}`, {
form: {
key: this.options.authkey
}
Expand Down
24 changes: 22 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,19 @@ describe('mip-cache', () => {
});
});
});

it('https', () => {
return app.clear('https://mip.xuexb.com').catch(err => {
expect(err).to.deep.equal({
status: 1,
msg: 'auth check fail'
});
});
});
});

if (process.env.MIP_CACHE_AUTHKEY) {
it('post zhanzhang.baidu.com', () => {
it('https', () => {
return new MipCache({
authkey: process.env.MIP_CACHE_AUTHKEY
}).clear('https://mip.xuexb.com').then(data => {
Expand All @@ -123,10 +132,21 @@ describe('mip-cache', () => {
});
});

it('post zhanzhang.baidu.com', () => {
return new MipCache({
authkey: process.env.MIP_CACHE_AUTHKEY
}).clear('http://mip.xuexb.com').then(data => {
expect(data).to.deep.equal({
status: 0,
msg: 'cache clean success'
});
});
});

it('post zhanzhang.baidu.com is error', () => {
return new MipCache({
authkey: process.env.MIP_CACHE_AUTHKEY
}).clear('https://mip.xuexb.com/post/xiaowu.html').then(data => {
}).clear('http://mip.xuexb.com/post/xiaowu.html').then(data => {
expect(data).to.deep.equal({
status: 0,
msg: 'cache clean success'
Expand Down

0 comments on commit bf99a24

Please sign in to comment.