Use external service for rss xml to json
This commit is contained in:
parent
f1c02ca7e5
commit
3f54fb8a2a
4 changed files with 7 additions and 26 deletions
|
@ -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"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
Loading…
Reference in a new issue