Skip to content

Commit

Permalink
feat: support apiEndpoint override (#728)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored and stephenplusplus committed May 31, 2019
1 parent 988345d commit 61eeb64
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@
"predocs-test": "npm run docs"
},
"dependencies": {
"@google-cloud/common": "^1.0.0",
"@google-cloud/common": "^2.0.0",
"@google-cloud/paginator": "^1.0.0",
"@google-cloud/promisify": "^1.0.0",
"@types/protobufjs": "^6.0.0",
"arrify": "^2.0.0",
"compressible": "^2.0.12",
"concat-stream": "^2.0.0",
Expand Down
9 changes: 8 additions & 1 deletion src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export interface StorageOptions extends GoogleAuthOptions {
autoRetry?: boolean;
maxRetries?: number;
promise?: typeof Promise;
/**
* The API endpoint of the service used to make requests.
* Defaults to `www.googleapis.com`.
*/
apiEndpoint?: string;
}

export interface BucketOptions {
Expand Down Expand Up @@ -285,8 +290,10 @@ export class Storage extends Service {
* @param {StorageOptions} [options] Configuration options.
*/
constructor(options: StorageOptions = {}) {
options.apiEndpoint = options.apiEndpoint || 'www.googleapis.com';
const config = {
baseUrl: 'https://www.googleapis.com/storage/v1',
apiEndpoint: options.apiEndpoint,
baseUrl: `https://${options.apiEndpoint}/storage/v1`,
projectIdRequired: false,
scopes: [
'https://www.googleapis.com/auth/iam',
Expand Down
14 changes: 14 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ describe('Storage', () => {
require('../../package.json')
);
});

it('should propagate the apiEndpoint option', () => {
const apiEndpoint = 'some.fake.endpoint';
storage = new Storage({
projectId: PROJECT_ID,
apiEndpoint,
});
const calledWith = storage.calledWith_[0];
assert.strictEqual(
calledWith.baseUrl,
`https://${apiEndpoint}/storage/v1`
);
assert.strictEqual(calledWith.apiEndpoint, apiEndpoint);
});
});

describe('bucket', () => {
Expand Down

0 comments on commit 61eeb64

Please sign in to comment.