I want to handle SPA on path /app/*.
There is only one way to do this: define root 404.astro and inject SPA entry. But it's unobvious and also requires to load js chunk to show 404, even if current subpath is not related to app at all (imagine routes: /app/*, /blog/[article], /blog/404).
I think Astro should search for closest 404 page in a tree if requested path wasn't found.
Cloudflare Pages have exact behaviour: https://developers.cloudflare.com/pages/platform/serving-pages/#not-found-behavior.
I created topic here: https://github.com/withastro/rfcs/discussions/361
However, I want to implement it via integration API, and my question is:
how to render HTML output from server middleware?
'astro:server:setup'({ server }) {
server.middlewares.use(async (req, res, next) => {
// ...
const closest404Path = /*found path*/
const result = await server.ssrLoadModule(closest404Path, {
fixStacktrace: true,
})
// how to render loaded .astro module?
})
}