Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content-Type, and potentially other headers, for the different types of feeds #190

Open
Svish opened this issue Jun 24, 2023 · 3 comments
Open

Comments

@Svish
Copy link

Svish commented Jun 24, 2023

Is your feature request related to a problem? Please describe.
Writing routes in Next.js which will return feeds generated by this library, but unsure
what headers to send with the response.

import { NextResponse } from 'next/server'
import { createFeed } from '@/feed'

export async function GET() {
  const feed = createFeed()

  return new NextResponse(feed.rss2(), {
    headers: {
      'content-type': 'text/xml; charset=utf-8', // Hopefully correct ... ?
    },
  })
}

Describe the solution you'd like
The current .rss2(), .atom1() and .json1() functions just return a string. Would be great if there were alternatives to those which simply returned standard Response objects with the rendered feed as the body and appropriate headers already setup.

import { createFeed } from '@/feed'

export async function GET() {
  return createFeed().toResponse('rss2')
}

Describe alternatives you've considered
Can of course just do it manually, like everyone else using this are probably doing, but I'm guessing that serving the rendered string from a server is probably one of the most common things to do with this library, so would be great if this could be handled right out of the box. 🧙‍♂️

@Svish
Copy link
Author

Svish commented Jun 24, 2023

Would also be cool if there was a cache header related to the ttl added on the feed, or something like that.

@webketje
Copy link

webketje commented Jul 6, 2023

Proper type for RSS is application/rss+xml. IMO you bring up a valid concern: users are not sure which content type headers to match to different feed outputs, and most uses of this library will at some point involve serving its output, whether it be through a Node server or through Apache or Nginx as the output of a Node static site generator.

But I think the solution would simply be to add a Serving feeds section in the docs mentioning the matching content types OR to change the output of the feed methods to return an object with properties, eg const returnValue = new String('...'); returnValue.contentType = 'application/rss+xml' (using new String in example to avoid breaking change)

Cache headers IMO are out of scope for a data-format rendering library

@Svish
Copy link
Author

Svish commented Jul 7, 2023

@webketje That sounds good to me, would be very helpful, without changing the scope of the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants