Skip to content

Commit 61eeb64

Browse files
JustinBeckwithstephenplusplus
authored andcommitted
feat: support apiEndpoint override (#728)
1 parent 988345d commit 61eeb64

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@
5050
"predocs-test": "npm run docs"
5151
},
5252
"dependencies": {
53-
"@google-cloud/common": "^1.0.0",
53+
"@google-cloud/common": "^2.0.0",
5454
"@google-cloud/paginator": "^1.0.0",
5555
"@google-cloud/promisify": "^1.0.0",
56-
"@types/protobufjs": "^6.0.0",
5756
"arrify": "^2.0.0",
5857
"compressible": "^2.0.12",
5958
"concat-stream": "^2.0.0",

src/storage.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export interface StorageOptions extends GoogleAuthOptions {
5050
autoRetry?: boolean;
5151
maxRetries?: number;
5252
promise?: typeof Promise;
53+
/**
54+
* The API endpoint of the service used to make requests.
55+
* Defaults to `www.googleapis.com`.
56+
*/
57+
apiEndpoint?: string;
5358
}
5459

5560
export interface BucketOptions {
@@ -285,8 +290,10 @@ export class Storage extends Service {
285290
* @param {StorageOptions} [options] Configuration options.
286291
*/
287292
constructor(options: StorageOptions = {}) {
293+
options.apiEndpoint = options.apiEndpoint || 'www.googleapis.com';
288294
const config = {
289-
baseUrl: 'https://www.googleapis.com/storage/v1',
295+
apiEndpoint: options.apiEndpoint,
296+
baseUrl: `https://${options.apiEndpoint}/storage/v1`,
290297
projectIdRequired: false,
291298
scopes: [
292299
'https://www.googleapis.com/auth/iam',

test/index.ts

+14
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,20 @@ describe('Storage', () => {
134134
require('../../package.json')
135135
);
136136
});
137+
138+
it('should propagate the apiEndpoint option', () => {
139+
const apiEndpoint = 'some.fake.endpoint';
140+
storage = new Storage({
141+
projectId: PROJECT_ID,
142+
apiEndpoint,
143+
});
144+
const calledWith = storage.calledWith_[0];
145+
assert.strictEqual(
146+
calledWith.baseUrl,
147+
`https://${apiEndpoint}/storage/v1`
148+
);
149+
assert.strictEqual(calledWith.apiEndpoint, apiEndpoint);
150+
});
137151
});
138152

139153
describe('bucket', () => {

0 commit comments

Comments
 (0)