Search code examples
angulartypescriptnpmrss

How can I make an Angular app output an RSS feed?


I've got an Angular site (v12 or something) which I built using the Angular CLI and I need to have it output an RSS feed.

I figure I can use something like the rss package on npm to actually construct the feed's contents, what I'm not clear on is how to have it output the RSS feed's contents instead of HTML. As in, instead of using the root-level index.html file and outputting the app component's contents, just hijack the HTML response entirely and, for the /rss route or whatever, have it output the RSS XML.

I can find tons of info online on how to have an Angular app read RSS feeds, but almost nothing about having it serve an RSS feed, which gives me a sneaking suspicion that I'm approaching the issue all wrong. More than one solution online shows how to have Angular write a file to your server which just seems like a horrible idea. I did something like this ages ago with ASP.NET which made me figure it would be possible with Angular but I'm coming up blank.


Solution

  • Angular is a SPA framework. It it built from JavaScript running inside an HTML document.

    An RSS feed is not an HTML document, so you can't run an Angular application inside it.

    Generating the RSS feed as a side effect of building the application is a perfectly reasonable approach so long as you are using some form of Static Site Generation (I'm not very familiar with Angular approaches to this, but that's the technique I use in a React/Next.JS site).

    If you aren't using Static Site Generation then some other approach might be better, likely one that bypassed any kind of Angular code you have entirely (e.g. a server side program that directly accesses the same data source as the client-side Angular code).