npm.io
0.1.0 • Published 7 years ago

gcframe-retry

Licence
MIT
Version
0.1.0
Deps
1
Size
812 B
Vulns
0
Weekly
0
Stars
6

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);
}

View Router docs

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)
}

View Cors docs

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);
}

View Auth docs

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),
}