docs: add experimental advanced routing reference page#13792
docs: add experimental advanced routing reference page#13792
Conversation
✅ Deploy Preview for astro-docs-2 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
…ing.mdx Co-authored-by: Yan <61414485+yanthomasdev@users.noreply.github.com>
ArmandPhilippot
left a comment
There was a problem hiding this comment.
Thanks Matthew, the wording looks good to me! No suggestions to improve that, only for the formatting:
- We usually don't put the arguments in the headings (ie.
middleware()instead ofmiddleware(state, next)). This helps make the links easier to parse when sharing them:#middlewareinstead of#middlewarestate-next - I think an API block for the methods is also helpful since some of them have different arguments or different return types.
I also noticed a few em dashes. We usually don't use them in docs. I don't know if we want to stay consistent with this or not. I don't have a strong opinion.
Question: Do we need a section for ContextProvider?
I see that the FetchState types often refer to create and finalize. Maybe it would be helpful to document it so we can link to ContextProvider.create() and ContextProvider.finalize(). I think this helps users navigate easily to between related sections.
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx Co-authored-by: Armand Philippot <git@armand.philippot.eu>
yanthomasdev
left a comment
There was a problem hiding this comment.
Thanks @matthewp, just adding a few suggestions to remove all these emdashes that are not necessary, and then LGTM
|
|
||
| The main benefit of advanced routing is the ability to insert custom logic anywhere in the request pipeline. You can run code before Astro touches the request, between pipeline stages, or after the response is produced. | ||
|
|
||
| The [`astro()` handler](#astro) is the simplest way to add pre- or post-processing around the full pipeline. When you need to insert logic *between* specific stages — for example, running custom code after actions but before page rendering — compose the individual handlers instead: |
There was a problem hiding this comment.
I'll say we should keep it consistent without emdashes.
| The [`astro()` handler](#astro) is the simplest way to add pre- or post-processing around the full pipeline. When you need to insert logic *between* specific stages — for example, running custom code after actions but before page rendering — compose the individual handlers instead: | |
| The [`astro()` handler](#astro) is the simplest way to add pre- or post-processing around the full pipeline. When you need to insert logic *between* specific stages, such as running custom code after actions but before page rendering, compose the individual handlers instead: |
|
|
||
| If no `src/app.ts` file exists (or `advancedRouting` is not enabled), Astro uses its built-in pipeline, which runs all features automatically. | ||
|
|
||
| ### Using `astro()` — the simplest approach |
There was a problem hiding this comment.
Safe to remove the subheading of the subheading 😅
| ### Using `astro()` — the simplest approach | |
| ### Using `astro()` |
| async fetch(request: Request): Promise<Response> { | ||
| const state = new FetchState(request); | ||
|
|
||
| // Custom pre-processing — runs before any Astro handler |
There was a problem hiding this comment.
| // Custom pre-processing — runs before any Astro handler | |
| // Custom pre-processing, runs before any Astro handler |
|
|
||
| const response = await astro(state); | ||
|
|
||
| // Custom post-processing — runs after Astro renders |
There was a problem hiding this comment.
| // Custom post-processing — runs after Astro renders | |
| // Custom post-processing, runs after Astro renders |
| }; | ||
| ``` | ||
|
|
||
| For many use cases — adding auth guards, request logging, custom headers — `astro()` is all you need. |
There was a problem hiding this comment.
| For many use cases — adding auth guards, request logging, custom headers — `astro()` is all you need. | |
| For many use cases, such as adding auth guards, request logging, and custom headers, `astro()` is all you need. |
| **Type:** <code>(state: <a href="#fetchstate">FetchState</a>) => Promise\<Response\></code> | ||
| </p> | ||
|
|
||
| Dispatches the request to the matched Astro route (page, endpoint, or fallback). This is the core rendering handler — most custom pipelines will include it. |
There was a problem hiding this comment.
| Dispatches the request to the matched Astro route (page, endpoint, or fallback). This is the core rendering handler — most custom pipelines will include it. | |
| Dispatches the request to the matched Astro route (page, endpoint, or fallback). This is the core rendering handler, and most custom pipelines will include it. |
| **Type:** <code>(state: <a href="#fetchstate">FetchState</a>, next: (state: FetchState) => Promise\<Response\>) => Promise\<Response\></code> | ||
| </p> | ||
|
|
||
| Runs Astro's middleware chain (from `src/middleware.ts`). The `next` callback is called at the bottom of the chain to produce the response — typically by calling `pages()`: |
There was a problem hiding this comment.
| Runs Astro's middleware chain (from `src/middleware.ts`). The `next` callback is called at the bottom of the chain to produce the response — typically by calling `pages()`: | |
| Runs Astro's middleware chain (from `src/middleware.ts`). The `next` callback is called at the bottom of the chain to produce the response, typically by calling `pages()`: |
Description (required)
Documents the upcoming
experimental.advancedRoutingflag.For Astro version:
6.2. See astro PR #16366.