lessworkjs / framework

The framework for lesswork.
https://lesswork.io
MIT License
2 stars 1 forks source link

Support more serverless providers #3

Open gcphost opened 6 years ago

gcphost commented 6 years ago

I want the package to support everything serverless supports if reasonable.

There are Response, Request, State, and Config classes.

Response

Controls how the callback is reported to the provider.

Request

Controls how we receive data from the State

State

Controls how we receive data from the provider.

Config

Controls how the serverless.js configuration is made.

gcphost commented 6 years ago

Looking over the examples we can see some subtle changes between the providers.

Google

exports.http = (request, response) => {
  response.status(200).send('Hello World!');
};

Openwhisk

'use strict';

const moment = require('moment-timezone');

function time(params) {
  const timezone = params.timezone || 'Europe/London';
  const timestr = moment().tz(timezone).format('HH:MM:ss');

  return { payload: `The time in ${timezone} is: ${timestr}.` };
}

module.exports.time = time;

Functions http event is different

functions:
  time:
    handler: handler.time
    events:
      - http: GET time

Azure

'use strict';

module.exports.hello = (context, req) => {
  context.log('JavaScript HTTP trigger function processed a request.');

  const res = {};

  if (req.query.name || (req.body && req.body.name)) {
    const name = req.query.name || req.body.name;

    res.body = `Hello ${name}`;
  } else {
    res.status = 400;
    res.body = 'Please pass a name on the query string or in the request body';
  }

  context.done(null, res);
};

Functions http..

functions:
  hello:
     handler: handler.hello
     events:
       - http: true
         x-azure-settings:
           authLevel: anonymous
gcphost commented 6 years ago

Also move the current classes to their own sub folder and have them extend generic base classes