Skip to content

Commit

Permalink
Merge pull request #126 from Starefossen/patch-1
Browse files Browse the repository at this point in the history
fix(upload): correct url for cn-north-1 S3 region
  • Loading branch information
Starefossen authored Nov 24, 2016
2 parents ed2f328 + ebb4dcc commit a08a633
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 8 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand Down

0 comments on commit a08a633

Please sign in to comment.