1 Star 0 Fork 0

ineo6/fetch-rss

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
server.js 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
ineo6 提交于 2015-06-27 20:11 . config complete
/**
* Module dependencies.
*/
'use strict';
var logger = require('koa-logger'),
route = require('koa-route'),
parse = require('co-body'),
koa = require('koa'),
render = require('./lib/render'),
factory = require('./lib/factory'),
schedule = require('node-schedule'),
co = require("co"),
config = require('./config/global');
co(function*() {
// Runs immedischeduleJobately on startup
schedule.scheduleJob(config.cron, function scheduledJob() {
co(siteTriger());
});
});
var app = koa();
// "database"
// middleware
app.use(logger());
// route middleware
app.use(route.get('/', home));
//app.use(route.get('/weixin/:id', weixin));
app.use(route.get('/site', site));
// route definitions
/**
* home
*/
function* home() {
this.body = yield render('home', {
count: 1
});
}
/**
* weixin-rss builder
*/
function* weixin(id) {
try {
var handler = factory.create('weixin', id);
var data = yield handler.getData();
this.type = 'text/xml; charset=UTF-8';
this.body = yield render('weixin', {
rss: data
});
} catch (err) {
console.log(err);
this.body = err.message;
}
}
//定时抓取页面
function* siteTriger() {
try {
var handler = factory.create('site');
yield handler.fetchData();
} catch (err) {
logger.error('ERROR fetch triger:\n', err);
}
}
function* site() {
try {
var handler = factory.create('site');
var data = yield handler.getData();
this.type = 'text/xml; charset=UTF-8';
this.body = yield render('site', {
rss: data
});
} catch (err) {
console.log(err);
}
}
// listen
app.listen(config.port, config.ipaddress);
console.log('listening on ip ' + config.ipaddress + ',port ' + config.port);
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ineo6/fetch-rss.git
git@gitee.com:ineo6/fetch-rss.git
ineo6
fetch-rss
fetch-rss
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385