File tree Expand file tree Collapse file tree 3 files changed +17
-3
lines changed Expand file tree Collapse file tree 3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -280,7 +280,6 @@ var S3Adapter = require("@parse/s3-files-adapter");
280280var AWS = require (" aws-sdk" );
281281
282282// Configure Digital Ocean Spaces EndPoint
283- const spacesEndpoint = new AWS.Endpoint (process .env .SPACES_ENDPOINT );
284283var s3Options = {
285284 bucket: process .env .SPACES_BUCKET_NAME ,
286285 baseUrl: process .env .SPACES_BASE_URL ,
@@ -293,7 +292,7 @@ var s3Options = {
293292 s3overrides: {
294293 accessKeyId: process .env .SPACES_ACCESS_KEY ,
295294 secretAccessKey: process .env .SPACES_SECRET_KEY ,
296- endpoint: spacesEndpoint
295+ endpoint: process . env . SPACES_ENDPOINT
297296 }
298297};
299298
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ class S3Adapter {
7373 this . _presignedUrlExpires = parseInt ( options . presignedUrlExpires , 10 ) ;
7474 this . _encryption = options . ServerSideEncryption ;
7575 this . _generateKey = options . generateKey ;
76+ this . _endpoint = options . s3overrides ?. endpoint ;
7677 // Optional FilesAdaptor method
7778 this . validateFilename = options . validateFilename ;
7879
@@ -157,7 +158,8 @@ class S3Adapter {
157158 await this . createBucket ( ) ;
158159 const command = new PutObjectCommand ( params ) ;
159160 const response = await this . _s3Client . send ( command ) ;
160- const location = `https://${ this . _bucket } .s3.${ this . _region } .amazonaws.com/${ params . Key } ` ;
161+ const endpoint = this . _endpoint || `https://${ this . _bucket } .s3.${ this . _region } .amazonaws.com` ;
162+ const location = `${ endpoint } /${ params . Key } ` ;
161163
162164 return Object . assign ( response || { } , { Location : location } ) ;
163165 }
Original file line number Diff line number Diff line change @@ -153,6 +153,7 @@ describe('S3Adapter tests', () => {
153153 s3overrides : { endpoint : otherEndpoint } ,
154154 } ;
155155 const s3 = new S3Adapter ( confObj ) ;
156+ expect ( s3 . _endpoint ) . toEqual ( otherEndpoint ) ;
156157 const endpointFromConfig = await s3 . _s3Client . config . endpoint ( ) ;
157158 expect ( endpointFromConfig . protocol ) . toEqual ( 'https:' ) ;
158159 expect ( endpointFromConfig . path ) . toEqual ( '/path' ) ;
@@ -161,6 +162,18 @@ describe('S3Adapter tests', () => {
161162 expect ( endpointFromConfig . query . foo ) . toEqual ( 'bar' ) ;
162163 } ) ;
163164
165+ it ( "should have undefined endpoint if no custom endpoint is provided" , async ( ) => {
166+ const confObj = {
167+ bucketPrefix : 'test/' ,
168+ bucket : 'bucket-1' ,
169+ secretKey : 'secret-1' ,
170+ accessKey : 'key-1' ,
171+ } ;
172+ const s3 = new S3Adapter ( confObj ) ;
173+ const endpoint = await s3 . _s3Client . config . endpoint ?. ( ) ;
174+ expect ( endpoint ) . toBeUndefined ( ) ;
175+ } ) ;
176+
164177 it ( 'should accept options and overrides as args' , ( ) => {
165178 const confObj = {
166179 bucketPrefix : 'test/' ,
You can’t perform that action at this time.
0 commit comments