I built this as an experiment with Cloudflare's Worker Script.<p>Here's a bit behind this app.<p>- Frontend: Just few lines of code using Svelte<p>- Backend: a Worker Script using Rust, here's how I do the RSS to JSON stuff:<p><pre><code> #[wasm_bindgen]
pub fn parse(content: &str) -> String {
let feed: Option<rss::Channel> = match content.parse::<Feed>().unwrap() {
Feed::RSS(rss_feed) => Some(rss_feed),
_ => None
};
if feed.is_some() {
let rss_feed = feed.unwrap();
let items: Vec<serde_json::Value> = rss_feed.items.iter().map(|item: &rss::Item| {
return json!({
"title": item.title.as_ref(),
"link": item.link.as_ref(),
"date": item.pub_date.as_ref(),
});
}).collect();
return json!({ "feed": items }).to_string();
}
return "".to_string();
}
</code></pre>
The only overhead, I think, is the part that I have to actually write the code to fetch RSS content in JavaScript (worker.js), as fool as you can imagine:<p><pre><code> const url = request.url.match(/url=(.*)/);
if (url && url.length > 1) {
const feeds = url[1].split(',');
let promises = feeds.map(async url => {
const res = await fetch(url);
const text = await res.text();
const json = JSON.parse(parse(text));
return json && json.feed || [];
});
let result = await Promise.all(promises);
let combined = result.reduce((arr, feed) => {
arr = arr.concat(feed);
return arr;
}, []);
return new Response(JSON.stringify({ "items": combined }), {status: 200, headers: {
'Content-Type': 'application/json'
}});
}
</code></pre>
If network libraries such as `reqwest`, and some date parser libraries like `chrono` already supported WASM, I'd be able to skip this JS step for good.<p>Deployed on Cloudflare using Wrangler CLI, I'm still on my free plan, and I hope I won't hit a 100k requests/day limit anytime soon.
It is cool, but it is not really an application in the expected sense. It is just a 2 stage RSS to HTML converter (e.g. RSS->JSON server, JSON->HTML client).<p>Not sure why not make just do RSS->HTML directly on the server.<p>Obviously, does not track read state or sync, or anything else basically.