A CORS proxy server for fetching RSS sources written in Deno, can be used with Deno Deploy.
It is relatively easy to parse RSS in browser because there is the DOMParser
API.
So one can try write an RSS reader in JS that runs on localhost.
But most RSS sources cannot be simply fetch
ed locally because of CORS policy.
One workaround would be a proxy server that retrieves RSS sources and adds CORS header to allow local consuming.
┌───────┐ ┌─────┐ ┌──────┐
│Browser│ │Proxy│ │Target│
└───┬───┘ └──┬──┘ └──┬───┘
│ │ │
│ CORS fetch() │ │
│──────────────>│ │
│ │ │
│ │ fetch() │
│ │─────────>│
│ │ │
│ │Response()│
│ │<─────────│
│ │ │
│CORS Response()│ │
│<──────────────│ │
┌───┴───┐ ┌──┴──┐ ┌──┴───┐
│Browser│ │Proxy│ │Target│
└───────┘ └─────┘ └──────┘
There is no stable native fetch
API in Node.js LTS yet, but Deno has. And like Node, only a few lines are needed to start a webserver in Deno.
This project takes a target RSS feed URL, fetches the content and sends to response with added CORS header.
Inspired by this repo.
You need to deploy this code on a server that runs Deno.
The easiest way would be to use Deno Deploy. Create a new playground, paste the code and deploy.
To use, visit https://[your-deploy-id].deno.dev/?target=RSS_URL
, and make sure "RSS_URL" is encoded with encodeURIComponent()
.
Example: to fetch https://hnrss.org/frontpage
locally:
- Encode the URL to
https%3A%2F%2Fhnrss.org%2Ffrontpage
. - Visit
https://[your-deploy-id].deno.dev/?target=https%3A%2F%2Fhnrss.org%2Ffrontpage
to get the proxy-ed response.