0.1.0 • Published 7 years ago
gcframe-retry v0.1.0
GCFrame
GCFrame helps serve HTTP endpoints with Google Cloud Functions.
There's a bunch of common things you probably want to do when serving HTTP endpoints via Google Cloud Functions. These micro libraries help out with that. The hope is that they become obsolete once Google implement further features into the Cloud Functions product.
Functions
Router
npm install -s gcframe-router
function helloWorld (req, res) {
return res.send(`Hello ${req.params.name});
}
module.exports = {
helloWorld: router('GET', '/:name', helloWorld);
}
Environment Variables
npm install -s gcframe-env
function helloWorld (req, res) {
return res.send(`Hello ${req.params.name});
}
module.exports = {
helloWorld: env.remoteConfig('remote-config', callback, helloWorld);
}
View Environment Variables docs
Cors
npm install -s gcframe-cors
function helloWorld (req, res) {
return res.send('Hello World');
}
module.exports = {
helloWorld: cors({ allowOrigin: '*', allowMethods: 'POST' }, helloWorld)
}
Auth
npm install -s gcframe-auth
function helloWorld (req, res) {
return res.send(`Hello ${req.params.name});
}
module.exports = {
helloWorld: auth({ authBucket: 'gcs-bucket-proxying-auth' }, helloWorld);
}
Composition
These functions are auto-curried handler-last functions, so they can be composed in a functional style.
function helloWorld (req, res) {
return res.send(`Hello ${req.params.name});
}
const handle = compose(
auth({ authBucket: 'my-auth-bucket' }),
cors({ allowOrigin: '*' }),
router('GET', '/:name'),
)
module.exports = {
helloWorld: handle(helloWorld),
}