stacker.news/pages/rss.js

25 lines
627 B
JavaScript
Raw Normal View History

2021-07-23 15:45:09 +00:00
2021-09-30 16:03:43 +00:00
import getSSRApolloClient from '../api/ssrApollo'
2021-07-23 15:45:09 +00:00
import generateRssFeed from '../lib/rss'
2022-02-17 17:23:43 +00:00
import { ITEMS } from '../fragments/items'
2021-07-23 15:45:09 +00:00
export default function RssFeed () {
return null
}
2021-08-09 19:47:39 +00:00
export async function getServerSideProps ({ req, res }) {
2021-07-23 15:45:09 +00:00
const emptyProps = { props: {} } // to avoid server side warnings
2021-09-30 16:03:43 +00:00
const client = await getSSRApolloClient(req)
2022-02-17 17:23:43 +00:00
const { error, data: { items: { items } } } = await client.query({
query: ITEMS
2021-07-23 15:45:09 +00:00
})
2021-08-09 19:47:39 +00:00
if (!items || error) return emptyProps
2021-07-23 15:45:09 +00:00
2022-01-07 21:29:38 +00:00
res.setHeader('Content-Type', 'text/xml; charset=utf-8')
2021-08-09 19:47:39 +00:00
res.write(generateRssFeed(items))
2021-07-23 15:45:09 +00:00
res.end()
return emptyProps
}