Use external service for rss xml to json

This commit is contained in:
syuilo 2017-05-25 14:52:22 +09:00
parent 9d28d73049
commit d62b1bbfa9
4 changed files with 7 additions and 26 deletions

View file

@ -147,7 +147,6 @@
"typescript": "2.3.3", "typescript": "2.3.3",
"uuid": "3.0.1", "uuid": "3.0.1",
"vhost": "3.0.2", "vhost": "3.0.2",
"websocket": "1.0.24", "websocket": "1.0.24"
"xml2json": "0.11.0"
} }
} }

View file

@ -64,8 +64,6 @@
</style> </style>
<script> <script>
this.mixin('api');
this.url = 'http://news.yahoo.co.jp/pickup/rss.xml'; this.url = 'http://news.yahoo.co.jp/pickup/rss.xml';
this.items = []; this.items = [];
this.initializing = true; this.initializing = true;
@ -80,12 +78,12 @@
}); });
this.fetch = () => { this.fetch = () => {
this.api('/api:rss', { fetch(`https://api.rss2json.com/v1/api.json?rss_url=${this.url}`).then(res => {
url: this.url res.json().then(feed => {
}).then(feed => { this.update({
this.update({ initializing: false,
initializing: false, items: feed.items
items: feed.rss.channel.item });
}); });
}); });
}; };

View file

@ -47,7 +47,6 @@ app.use('/assets', express.static(`${__dirname}/assets`, {
* Common API * Common API
*/ */
app.get(/\/api:url/, require('./service/url-preview')); app.get(/\/api:url/, require('./service/url-preview'));
app.post(/\/api:rss/, require('./service/rss-proxy'));
/** /**
* Serve config * Serve config

View file

@ -1,15 +0,0 @@
import * as express from 'express';
import * as request from 'request';
import xml2json = require('xml2json');
module.exports = (req: express.Request, res: express.Response) => {
const url: string = req.body.url;
request(url, (err, response, xml) => {
if (err) {
res.sendStatus(500);
} else {
res.send(xml2json.toJson(xml));
}
});
};