Simple functions emulator for local development
-p, --port
: specify emulator port to run, defaults to32245
-s, --functionsPath
: specify a path to look for functions, defaults tofunctions
-f, --functions
: specify which functions to run on emulator, if not present, runs all functions.
npm start -- -s examples
or npm start -- -s example -f echo,hello-world
Each function should export default one function to be used by server. Additionally you can export an init
function to do some work before the function is registered.
Example:
// ./examples/react-ssr/index.js
const utils = require('./utils');
module.exports = function (context) {
const props = {
name: 'Stream'
}
const html = utils.renderClient(props);
return html;
}
module.exports.init = async function () {
const path = require('path');
const targetPath = path.resolve(__dirname, '../__react-app/dist/server.bundle.js');
await utils.downloadClient(targetPath);
}
This section is under development, currently there is only 1 parameter available for functions and it only has, request parameter comes from express.req oject
You need to create a functions.config.json
on the root level of your functions folder
name
: Required. Name of the function, this is used to call function from clipath
: Required. Function path to be exposed from serverentry
: Required. Entry file path of the functionmethod
: HTTP method for the function, defaults toGET
{
"functions": [
{
"name": "echo",
"path": "/echo",
"entry": "echo/index.js",
"method": "GET"
},
{
"name": "hello-world",
"path": "/hello-world",
"entry": "hello-world/index.js",
"method": "GET"
}
]
}
- Handle local function dependencies, thanks to nodejs module structre we might not need this for nodejs functions
- Figure out how to implement middlewares for nodejs applications
- Potentially add other languages in the long run