Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

Commit a08a633

Browse files
authored
Merge pull request #126 from Starefossen/patch-1
fix(upload): correct url for cn-north-1 S3 region
2 parents ed2f328 + ebb4dcc commit a08a633

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,10 @@ const Upload = function Upload(bucketName, opts) {
150150

151151
if (!this.opts.url && this.opts.aws.region === 'us-east-1') {
152152
this.opts.url = `https://s3.amazonaws.com/${bucketName}/`;
153+
} else if (!this.opts.url && this.opts.aws.region === 'cn-north-1') {
154+
this.opts.url = `https://s3.${this.opts.aws.region}.amazonaws.com/${bucketName}/`;
153155
} else if (!this.opts.url) {
154-
this.opts.url = [
155-
'https://s3-', this.opts.aws.region,
156-
'.amazonaws.com/', bucketName, '/',
157-
].join('');
156+
this.opts.url = `https://s3-${this.opts.aws.region}.amazonaws.com/${bucketName}/`;
158157
}
159158

160159
this._randomPath = this.opts.randomPath || uuid;

test/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,17 @@ describe('Upload', () => {
132132
url: 'https://s3.amazonaws.com/myBucket/',
133133
});
134134
});
135-
it('sets default url based on AWS region', () => {
136-
upload = new Upload('b', {
137-
aws: {
138-
region: 'my-region-1',
139-
},
140-
});
135+
136+
it('sets correct url for custom AWS region', () => {
137+
upload = new Upload('b', { aws: { region: 'my-region-1' } });
141138
assert.equal(upload.opts.url, 'https://s3-my-region-1.amazonaws.com/b/');
142139
});
143140

141+
it('sets correct url for cn-north-1 AWS region', () => {
142+
upload = new Upload('b', { aws: { region: 'cn-north-1' } });
143+
assert.equal(upload.opts.url, 'https://s3.cn-north-1.amazonaws.com/b/');
144+
});
145+
144146
it('sets custom url', () => {
145147
upload = new Upload('b', {
146148
url: 'http://cdn.app.com/',

0 commit comments

Comments
 (0)