5 Star 11 Fork 1

Cherokee/arex

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
server.js 1010 Bytes
一键复制 编辑 原始数据 按行查看 历史
Cherokee 提交于 2021-10-11 17:57 . http server
var http = require('http');
var httpreq = require('./lib/httprequest.js');
var arex = require('./lib/arex.js');
var hostname = '0.0.0.0';
var port = 3824;
var server = http.createServer((req, res) => {
var chunks = [];
req.on('data', chunk => chunks.push(chunk));
res.statusCode = 200;
req.on('end', () => {
res.setHeader('Content-Type', 'application/json');
try {
var data = Buffer.concat(chunks);
var json_data = JSON.parse(data.toString());
httpreq.get(json_data['url'],(err,body)=>{
if(err)res.end('{}');
else {
var result = arex.get_article_sync(body, json_data['size']||200, json_data['smooth']);
res.end(JSON.stringify(result));
}
});
} catch (e) {
//console.error(e);
res.end('{}');
}
});
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
NodeJS
1
https://gitee.com/dreamidea/arex.git
[email protected]:dreamidea/arex.git
dreamidea
arex
arex
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385