Use external service for rss xml to json

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

View file

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

View file

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

View file

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