I was able to generate an rss.xml file and write it fs.writefilesync. When viewed locally, it works, but on vercel, the build breaks and says "no such file or director ./public/rss.xml."
If I commnet out the fs.writefilesync line, the deployment and build completes but I get a 404 when visiting mysite.com/rss.xml. Any Idea how I can view the rss.xml file after deployment?
This is the generaterssfile in a utils folder
import fs from 'fs'
import { Feed } from "feed";
async function PostFeed(articles) {
const site_url='mysite.com';
const pubDate= new Date()
const author = 'Post Author'
const feed = new Feed({
title: 'mysite | RSS Feed',
description: '',
id: site_url,
link: site_url,
image: `${site_url}/favicon.ico`,
favicon: `${site_url }/favicon.ico`,
copyright: `All rights reserved ${pubDate.getFullYear()}, mysite`,
updated: pubDate,
date:pubDate,
generator: "Feed for mysite",
feedLinks: {
rss2: `${site_url}/rss.xml`,
json: `${site_url }/rss/feed.json`,
},
author,
});
await articles.forEach((post) => {
const url = `${site_url}/post/${post.node.slug}`;
feed.addItem({
title: post.node.title,
id: url,
link: url,
description: post.node.excerpt,
content: post.node.excerpt,
author: author ,
contributor: [author],
date: new Date(post.node.createdAt),
});
});
fs.writeFileSync("./public/rss.xml", feed.rss2(), { encoding: "utf-8" });
}
export default PostFeed
Then I call PostFeed in getServerSideProps in my index.js
There aren't any specific solutions.