diff --git a/index.js b/index.js index 3657990..087c6cc 100644 --- a/index.js +++ b/index.js @@ -150,11 +150,10 @@ const Upload = function Upload(bucketName, opts) { if (!this.opts.url && this.opts.aws.region === 'us-east-1') { this.opts.url = `https://s3.amazonaws.com/${bucketName}/`; + } else if (!this.opts.url && this.opts.aws.region === 'cn-north-1') { + this.opts.url = `https://s3.${this.opts.aws.region}.amazonaws.com/${bucketName}/`; } else if (!this.opts.url) { - this.opts.url = [ - 'https://s3-', this.opts.aws.region, - '.amazonaws.com/', bucketName, '/', - ].join(''); + this.opts.url = `https://s3-${this.opts.aws.region}.amazonaws.com/${bucketName}/`; } this._randomPath = this.opts.randomPath || uuid; diff --git a/test/index.js b/test/index.js index a685f28..2cf3217 100644 --- a/test/index.js +++ b/test/index.js @@ -132,15 +132,17 @@ describe('Upload', () => { url: 'https://s3.amazonaws.com/myBucket/', }); }); - it('sets default url based on AWS region', () => { - upload = new Upload('b', { - aws: { - region: 'my-region-1', - }, - }); + + it('sets correct url for custom AWS region', () => { + upload = new Upload('b', { aws: { region: 'my-region-1' } }); assert.equal(upload.opts.url, 'https://s3-my-region-1.amazonaws.com/b/'); }); + it('sets correct url for cn-north-1 AWS region', () => { + upload = new Upload('b', { aws: { region: 'cn-north-1' } }); + assert.equal(upload.opts.url, 'https://s3.cn-north-1.amazonaws.com/b/'); + }); + it('sets custom url', () => { upload = new Upload('b', { url: 'http://cdn.app.com/',