Enable Endpoints without extension #1020
Closed
regisphilibert
started this conversation in
Proposal
Replies: 2 comments 1 reply
-
Extensionless endpoints are the default, e.g. You are right though that because Astro ignores files starting with an underscore it is not so simple to create a file named, e.g. // src/pages/[redirects].ts
export function getStaticPaths() {
return [{ params: { redirects: '_redirects' } }];
}
export async function GET({ params, redirect }) {
const body = await getRedirects()
.map(({from, to, code, force}) => `${from} ${to} ${code}${force}`)
.join(" ")
return new Response(body);
} |
Beta Was this translation helpful? Give feedback.
1 reply
-
This is great! Thanks @delucis Don't think this proposal is relevant anymore. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
It is not currently possible to create an endpoint without an extension or with a underscore as prefix. This means you cannot create a
/_headers
endpoint or a/_redirects
endpoint.This proposal aims at allowing user to override the current route configuration inferred form the route filename.
Background & Motivation
The "route filename as a route setting" problem.
Currently endpoints URLs are limited by the page files "file naming" logic which act as sole route configuration. This means:
The Host Config File problem
Working with Netlify, there are several options to declare headers and redirect rules for your project. But as it is incredibly powerful and convenient to be able to dynamically generate those from the framework, many users rely on the ability to add to your built files a
_headers
or_redirects
(To benefit from CMS input or various factoring rules). The hose which those framework generated files reads as its own config files for the given rules.Because of the "filename as route setting" limitation discussed above, to provide Netlify or CloudFlare Pages with those files, you'd have to create a
/pages/redirects.txt.js
and then run amv
command after your build command to rename/redirects.txt
to/_redirects
Goals
_redirects
,_headers
,etc...
Example
This new filename information could be stored in a reserved exported const from the page file.
Taking this further
Even if this proposal does not have a concreate API suggestion to allow the same for SSR dynamic endpoints. This could be a future discussion in order to allow users to bring beautiful urls to their API. As I believe today, producing a
/api/document/03443
route is not possible. You'd have to content with something like/api/document/03443.json
This is minor but would be welcome by many.
Beta Was this translation helpful? Give feedback.
All reactions