Created
August 24, 2018 11:38
-
-
Save mafraba/756154a1d7b78b2b6f11549474982121 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Storage = require('@google-cloud/storage') | |
const storage = new Storage({ | |
projectId: 'myproject', | |
customEndpoint: true | |
}) | |
const googleStorageUrl = 'https://www.googleapis.com/storage/v1' | |
storage.interceptors.push({ | |
request: reqOpts => { | |
console.log(" * Original request: ", reqOpts) | |
if (reqOpts.uri.includes(googleStorageUrl)) { | |
reqOpts.uri = reqOpts.uri.replace(googleStorageUrl, 'http://localhost:9828') | |
console.log(" * Rewritten url: ", reqOpts) | |
} | |
return reqOpts | |
} | |
}) | |
const bucketName = 'mytestbucket' | |
// Creates the new bucket | |
storage | |
.createBucket(bucketName) | |
.then(() => { | |
console.log(`Bucket ${bucketName} created.`); | |
}) | |
.catch(err => { | |
console.error('ERROR:', err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment