diff --git a/docs/server.md b/docs/server.md index 1b03a26..910b311 100644 --- a/docs/server.md +++ b/docs/server.md @@ -124,6 +124,28 @@ Populate the `config.json` with the AWS region and bucket name you want to use, These can also be passed via the `AWS_REGION`, and `AWS_S3_BUCKET` environment variables if required. +To use a custom endpoint URL, you can use set the `endpoint` key in `config.json` or the environment variable `AWS_S3_ENDPOINT` to point to the endpoint URL. + +You can also use the `configArgs` key in `config.json` or environment variable `AWS_S3_CLIENT_ARGS` to pass arbitrary options to the AWS SDK client, as follows: + +```json +{ + "region": "eu-west-1", + "bucket": "hmn-uploads-eu", + "endpoint": "project-name.localhost", + "clientArgs": { + "s3BucketEndpoint": true, + } +} +``` + +OR + +```bash +export AWS_S3_ENDPOINT="project-name.localhost" +export AWS_S3_CLIENT_ARGS="s3BucketEndpoint=true" +``` + ### Running the server diff --git a/index.js b/index.js index 0797c77..e9497ff 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,7 @@ module.exports = {}; module.exports.s3 = function(config, key, args, callback) { AWS.config.region = config.region; - var s3config = {}; + var s3config = Object.assign( {}, config.clientArgs ); if (config.endpoint) { s3config.endpoint = config.endpoint; } diff --git a/proxy-file.js b/proxy-file.js index 0ed7588..8debe8a 100644 --- a/proxy-file.js +++ b/proxy-file.js @@ -3,7 +3,7 @@ const AWS = require( 'aws-sdk' ); const authenticatedRequest = !!process.env.S3_AUTHENTICATED_REQUEST ? process.env.S3_AUTHENTICATED_REQUEST.toLowerCase() === 'true' : false; function sendOriginal( config, bucket, key, callback ) { - const s3 = new AWS.S3(config); + const s3 = new AWS.S3( Object.assign( {}, config, config.clientArgs ) ); let request; if ( authenticatedRequest ) { diff --git a/server.js b/server.js index 08cb8d2..a3007e4 100644 --- a/server.js +++ b/server.js @@ -19,6 +19,11 @@ if ( process.env.AWS_REGION && process.env.AWS_S3_BUCKET ) { config = JSON.parse( fs.readFileSync( 'config.json' ) ); } +config.clientArgs = config.clientArgs || {}; +if ( process.env.AWS_S3_CLIENT_ARGS ) { + ( new url.URLSearchParams( process.env.AWS_S3_CLIENT_ARGS ) ).forEach( ( value, key ) => config.clientArgs[ key ] = value ); +} + http.createServer( function( request, response ) { var params = url.parse( request.url, true );