withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
45.84k stars 2.41k forks source link

Unable to generate RSS feed with directory format consistently across DEV and PROD environments #11447

Open eikowagenknecht opened 2 months ago

eikowagenknecht commented 2 months ago

Astro Info

Astro                    v4.11.5
Node                     v20.11.1
System                   Windows (x64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             @astrojs/tailwind
                         @astrojs/react
                         @astrojs/sitemap
                         @astrojs/mdx

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

For my site, I use the "directory" format: https://example.com/page/

I would like to have my RSS feed like this as well: https://example.com/feed/

But I can't find any combination of the generating endpoint file name, trailingSlash and build.format to achieve this.

File /pages/feed.js, trailingSlash: always, build.format: directory: -> DEV: /feed has a 404, /feed/ works. PROD: Generates /feed file, /feed/ has a 404

File /pages/feed/index.js, trailingSlash: always, build.format: directory: -> Same behaviour as /pages/feed.js

If it's not possible to put an RSS feed as a directory, I would be kind of content with just using /rss.xml, but that has it's own problem: It is not reachable on the DEV server any more.

File /pages/rss.xml.js, trailingSlash: always, build.format: directory: -> DEV: /rss.xml has a 404, /rss.xml/ works. PROD: Generates /rss.xml file, /rss.xml/ has a 404

What's the expected result?

There should be a combination of trailingShash and build.format that behaves consistently for DEV and PROD for endpoint routes.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-6vyntu

Participation

ematipico commented 2 months ago

Have you tried the build format preserve? https://docs.astro.build/en/reference/configuration-reference/#buildformat

I think that's what you're looking for...

eikowagenknecht commented 2 months ago

I've tried that one as well, the result is still the same for the feed:

File pages/feed.js, trailingSlash: always, build.format: preserve:

Also, all other links show in file style (e.g. https://example.com/blog instead of https://example.com/blog/) now, which is not what I want.

It seems like for endpoint rules (xyz.js files), no matter what is set as build.format, the output is always xyz.

feed.js > feed feed.xml.js > feed.xml feed/index.js > feed feed.xml/index.js > feed.xml feed.xml/index.html.js > feed.xml.html

All output is always in the root, no directory is created.

ematipico commented 1 month ago

Ok, I know what's the issue, and it's not the first one.

The issue is that we impose trailingSlash on endpoints too. It's not the first issue that was filed, however we can't change the behaviour lightly.

We plan to change this behaviour in Astro 5.0, by not applying trailingSlash to endpoints. This will be a breaking change.

The only workaround that I can suggest is to change is to use trailingSlash: ignore, however I know that probably won't solve your issue.