|
| 1 | +// Copyright 2022 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +/** |
| 16 | + * This application demonstrates set a custom endpoint with |
| 17 | + * the Google Cloud Storage API. |
| 18 | + * |
| 19 | + * For more information, see the README.md under /storage and the documentation |
| 20 | + * at https://cloud.google.com/storage/docs. |
| 21 | + */ |
| 22 | + |
| 23 | +function main(apiEndpoint = 'https://storage.googleapis.com') { |
| 24 | + // [START storage_set_client_endpoint] |
| 25 | + /** |
| 26 | + * TODO(developer): Uncomment the following lines before running the sample. |
| 27 | + */ |
| 28 | + // The custom endpoint to which requests should be made |
| 29 | + // const apiEndpoint = 'https://yourcustomendpoint.com'; |
| 30 | + |
| 31 | + // Imports the Google Cloud client library |
| 32 | + const {Storage} = require('@google-cloud/storage'); |
| 33 | + |
| 34 | + // Creates a client |
| 35 | + const storage = new Storage({ |
| 36 | + apiEndpoint: apiEndpoint, |
| 37 | + useAuthWithCustomEndpoint: true, |
| 38 | + }); |
| 39 | + |
| 40 | + console.log(`Client initiated with endpoint: ${storage.apiEndpoint}.`); |
| 41 | + |
| 42 | + // [END storage_set_client_endpoint] |
| 43 | +} |
| 44 | +process.on('unhandledRejection', err => { |
| 45 | + console.error(err.message); |
| 46 | + process.exitCode = 1; |
| 47 | +}); |
| 48 | +main(...process.argv.slice(2)); |
0 commit comments