withastro / astro

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

Static File Endpoints broken with `trailingSlash: "always"` in development #10149

Closed kripod closed 8 months ago

kripod commented 9 months ago

Astro Info

Astro                    v4.4.0
Node                     v20.10.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             astro-icon
                         @astrojs/mdx
                         @astrojs/sitemap
                         @astrojs/tailwind

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

No response

Describe the Bug

Since astro@4.1.0, Static File Endpoints return 404 in development (running astro dev) when trailingSlash: "always" is set in the Astro config.

What's the expected result?

Static File Endpoints should work as they did before merging https://github.com/withastro/astro/pull/9597.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-fy7uro?file=src%2Fpages%2Ftest.json.js

Participation

matthewp commented 8 months ago

Are they broken only in development (just to understand, obviously this is still very important).

kripod commented 8 months ago

Yes, the issue only occurs in dev mode.

ematipico commented 8 months ago

I'll look into it

ematipico commented 8 months ago

Hi @kripod, we talked about this internally.

This isn't a bug. We actually fixed that bug, and now the routing behaves consistently. As you set trailingSlash: always, it's expected that routes should respond to a trailing slash, endpoints too. Essentially, you were leveraging a bug.

I suggest using trailingSlash: ignore.

We will monitor the situation and see if this bugfix impacts too many users.

kripod commented 8 months ago

@ematipico I think my issue report may have been misunderstood.

Trailing slashes are a valid requirement for most API endpoint URLs, except for the ones which are meant to serve static files, e. g. .png images. Having to refer to those assets via /something.png/ instead of /something.png may be outright invalid in production, even when trailing slashes are preferred.

drewtownchi commented 5 months ago

We've been having this issue for months. We have a search.json.ts static file endpoint in the pages dir. In prod we need to not add a trailing slash to the end of the route and in dev we need to make sure there is a trailing slash. It's not an optimal situation.