Skip to content

Instantly share code, notes, and snippets.

@manobi
Created February 19, 2019 17:41
Show Gist options
  • Save manobi/c390933a987c9262c14e6fe97f70084a to your computer and use it in GitHub Desktop.
Save manobi/c390933a987c9262c14e6fe97f70084a to your computer and use it in GitHub Desktop.
FaaS comparison
//https://webtask.io/docs/model
module.exports = function(cb) {
cb(null, { i_am: 'done '});
}
//https://docs.aws.amazon.com/pt_br/lambda/latest/dg/nodejs-prog-model-handler.html
exports.myHandler = function(event, context, callback) {
... function code
callback(null, "some success message");
// or
// callback("some error type");
}
// You should include context, other arguments are optional
module.exports = function(context, myTrigger, myInput, myOtherInput) {
// function logic goes here :)
context.done();
};
addEventListener('fetch', event => {
event.respondWith(fetchAndApply(event.request))
})
async function fetchAndApply(request) {
if (request.headers.get('user-agent').includes('annoying_robot')) {
return new Response('Sorry, this page is not available.',
{ status: 403, statusText: 'Forbidden' })
}
return fetch(request)
}
const escapeHtml = require('escape-html');
/**
* HTTP Cloud Function.
*
* @param {Object} req Cloud Function request context.
* More info: https://expressjs.com/en/api.html#req
* @param {Object} res Cloud Function response context.
* More info: https://expressjs.com/en/api.html#res
*/
exports.helloHttp = (req, res) => {
res.send(`Hello ${escapeHtml(req.query.name || req.body.name || 'World')}!`);
};
const main = (params) => {
let body = `Hello ${params.name || 'World'}`
let res = {body}
return res
}
//https://fnproject.io/tutorials/node/intro/
const fdk=require('@fnproject/fdk');
fdk.handle(function(input){
let name = 'World';
if (input.name) {
name = input.name;
}
return {'message': 'Hello ' + name}
})
const { parse } = require('url')
module.exports = (req, res) => {
const { query } = parse(req.url, true)
const { name = 'World' } = query
res.end(`Hello ${name}!`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment