Aliyun-function-compat
阿里云函数计算适配器
阿里云的函数计算提供两种入口:普通函数和http函数
普通函数形如event, context, callback
http函数则是req, res, context
本工具包将两种函数转换为event, context
模式,并且使用async/await
来返回结果
使用方法
安装依赖
npm i aliyun-function-compat
编写代码
const compat = require('aliyun-function-compat')
exports.handler = compat(async (event, context) => {
await some()
if(events.method === 'POST') {
console.log(events.body.id)
}
throw new Error('some erorr message')
const err = new Error('error with code')
err.code = -1234
throw err
throw 'error message'
return { result:123 }
})