Created
February 19, 2019 17:41
-
-
Save manobi/c390933a987c9262c14e6fe97f70084a to your computer and use it in GitHub Desktop.
FaaS comparison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://webtask.io/docs/model | |
module.exports = function(cb) { | |
cb(null, { i_am: 'done '}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// You should include context, other arguments are optional | |
module.exports = function(context, myTrigger, myInput, myOtherInput) { | |
// function logic goes here :) | |
context.done(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')}!`); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const main = (params) => { | |
let body = `Hello ${params.name || 'World'}` | |
let res = {body} | |
return res | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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