diff --git a/src/index.js b/src/index.js index 2778aae..9c14645 100644 --- a/src/index.js +++ b/src/index.js @@ -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 } diff --git a/test/index.js b/test/index.js index 472eabc..6146b4b 100644 --- a/test/index.js +++ b/test/index.js @@ -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 => { @@ -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'