安装NodeJS
curl -sL https://rpm.nodesource.com/setup_10.x | bash - && yum install -y nodejs
安装Funcraft
npm install request @alicloud/fun -g
或者
npm --registry=https://registry.npm.taobao.org install request @alicloud/fun -g
本地配置
fun config
选择函数计算服务器
新建工作空间
mkdir search_ip && cd search_ip
新建一个HTTP函数触发器
fun init http-trigger-nodejs10
部署应用到函数计算服务
fun deploy -y
使用curl命令访问HTTP触发器
clientIP就是我们想要的地址
curl https://[阿里云ID].cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/search_ip/search_ip/
将 index.js 文件内容清空
cat /dev/null > index.js
编辑index.js
vim index.js
添加内容
var getRawBody = require('raw-body')
module.exports.handler = function (request, response, context) {
getRawBody(request, function (err, data) {
var respBody = new Buffer.from("您的IP是:" + request.clientIP);
response.setStatusCode(200)
response.setHeader('content-type', 'text/html')
response.send(respBody)
})
};
部署至函数计算服务中
fun deploy -y
使用curl命令访问HTTP触发器
curl https://[阿里云ID].cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/search_ip/search_ip/