Skip to content

Instantly share code, notes, and snippets.

@mafraba
Created August 24, 2018 11:38
Show Gist options
  • Save mafraba/756154a1d7b78b2b6f11549474982121 to your computer and use it in GitHub Desktop.
Save mafraba/756154a1d7b78b2b6f11549474982121 to your computer and use it in GitHub Desktop.
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