@haensl/google-cloud
v1.0.1
Published
Useful things around Google Cloud
Maintainers
Readme
@haensl/google-cloud
Useful utitlities for working in Google Cloud.
Installation
# via npm
npm i --save @haensl/google-cloudUsage
getAuthorization: async (url) => string
Get authorization to call a URL. This is useful to authorize requests between services within Google Cloud.
Parameters
url: string|URL
The URL you want to call.
Returns
The Authorization header for the request to the given URL.
Example: Authorizing a request
const { getAuthorization } = require('@haensl/google-cloud');
const fetch = require('node-fetch');
const callOtherService = async () => {
// ...
const otherService = new URL('https://myservice-1234567890.region.run.app');
const authorization = await getAuthorization(otherService);
const requestOptions = {
method: 'GET',
headers: {
'Authorization': authorization
}
};
const response = await fetch(otherService, requestOptions);
// ...
};
