合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
# 部署一个查询ip的接口 1.创建服务 2.创建函数 3.vs code 上传代码 ```js const { Server } = require('@webserverless/fc-express') const express = require('express'); const fs = require('fs'); const path = require('path'); const bodyParser = require('body-parser'); const searcher = require('node-ip2region').create(); const app = express(); app.get('\*', function(req, res) { var ip = req.query.ip if (ip == undefined) {         res.send({ "ip": null         }) return     } var data = searcher.memorySearchSync(ip) const { region } = data var arr = region.split("|") var redata = { "country": arr\[0\] == "0" ? '' : arr\[0\], "region": arr\[1\] == "0" ? '' : arr\[1\], "province": arr\[2\] == "0" ? '' : arr\[2\], "city": arr\[3\] == "0" ? '' : arr\[3\], "isp": arr\[4\] == "0" ? '' : arr\[4\],         } // \_城市Id|国家|区域|省份|城市|ISP\_     res.send(redata) }) const server = newServer(app); // http trigger entry module.exports.handler = function(req, res, context) {     server.httpProxy(req, res, context); }; ``` # 如图 ![](https://img.kancloud.cn/e5/2a/e52a26824524a1701f10e33d93ce1b17_1463x1611.png) # 绑定域名 ``` http://hkyun.rongyiapi.com/ipquery?ip=119.85.97.4 {"country": "中国","region": "","province": "重庆","city": "重庆市","isp": "电信"} ``` ![](https://img.kancloud.cn/18/90/189018d79eb75cfc790b6b89e7477473_1190x956.png) # 就是这么简单就创建好了一个函数了~