Make trailingSlashes optional for /api pages.
After updating to Next 9.5 and enabling trailing slashes my API calls started to report a 308 redirect header. This unfortunately broke some webhook integration because they weren't following the redirect.
Example:
/api/foo.js used to serve /api/foo, with trailingSlashes on /api/foo returns a 308 redirect to /api/foo/.
_A clear and concise description of what you want and what your use case is._
This isn't a huge issue for us since we just updated our various fetch calls, and integrations to use the trailing slashes, but it creates odd semantics around the API.
N/A
IMHO I think there should be a way to deactivate the 308 in all situations, not only in /api. Perhaps a regex of paths, allowing to disable the redirects in all paths too.
I'm going to try to explain our case. Before this trailingSlash feature was landed, no redirect was done. With this, using a custom server we implemented the "trailingSlash" feature on the custom server for our project. However, with a small difference:

We had implemented this in a similar way to:
server.all('*', (req, res) => {
const redirectUrl = redirectToTrailingSlash(req)
if (redirectUrl) {
res.redirect(308, redirectUrl)
return
}
req.url = clearTrailingSlash(req)
handle(req, res)
})
However, now, with the new trailingSlash feature, this is different:

With this small change, it causes that pages like /whatever first redirect to /whatever/ and then to 404. Maybe it sounds like a little nonsense, but it's a change we don't want to take on right now because of SEO.
We reported this issue here https://github.com/vercel/next.js/issues/16586, but it was closed at once by @timneutkens, saying that it is the expected behavior.
The reason is that we don't want a small degradation in SEO. A 308 redirect triggers a new crawl action to googlebot, and when you manage a large set of URLs, you want to avoid useless redirects. And setting trailingSlash=false is not an option, as it now forces redirects in the opposite direction, from /whatever/ to /whatever.

Since @timneutkens closed the issue and it seems that it's something that will not be changed (although I think it should be reconsidered), I think like you @michaelcamdencommon, that there should be a mechanism to be able to deactivate these redirects.
Most helpful comment
IMHO I think there should be a way to deactivate the 308 in all situations, not only in
/api. Perhaps a regex of paths, allowing to disable the redirects in all paths too.I'm going to try to explain our case. Before this
trailingSlashfeature was landed, no redirect was done. With this, using a custom server we implemented the "trailingSlash" feature on the custom server for our project. However, with a small difference:We had implemented this in a similar way to:
However, now, with the new
trailingSlashfeature, this is different:With this small change, it causes that pages like
/whateverfirst redirect to/whatever/and then to 404. Maybe it sounds like a little nonsense, but it's a change we don't want to take on right now because of SEO.We reported this issue here https://github.com/vercel/next.js/issues/16586, but it was closed at once by @timneutkens, saying that it is the expected behavior.
The reason is that we don't want a small degradation in SEO. A 308 redirect triggers a new crawl action to googlebot, and when you manage a large set of URLs, you want to avoid useless redirects. And setting
trailingSlash=falseis not an option, as it now forces redirects in the opposite direction, from/whatever/to/whatever.Since @timneutkens closed the issue and it seems that it's something that will not be changed (although I think it should be reconsidered), I think like you @michaelcamdencommon, that there should be a mechanism to be able to deactivate these redirects.