Open gcphost opened 6 years ago
Looking over the examples we can see some subtle changes between the providers.
exports.http = (request, response) => {
response.status(200).send('Hello World!');
};
'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
'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
Also move the current classes to their own sub folder and have them extend generic base classes
I want the package to support everything serverless supports if reasonable.
There are
Response
,Request
,State
, andConfig
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.