Export a page config for granular adapter configuration #656
Replies: 2 comments
-
I agree that this would be a great capability and it's sort of already there in the build hooks, but you kind of need to combine the info from two different build hooks to generate the file. I built this for SST to allow for an edge function to run route matching using the configured Astro routing. (Ref: https://github.com/sst/sst/pull/3176/files#diff-25c360f212ef7699942654556e68a5d71159d5a52a02d6434978cea614b7b885) The result is an {
"props": { "customDomain": "preview.zachcardoza.com" },
"buildConfig": {
"typesPath": "src",
"serverBuildOutputFile": "dist\\server\\entry.mjs",
"clientBuildOutputDir": "dist\\client",
"clientBuildVersionedSubDir": "static"
},
"astroSite": {
"outputMode": "hybrid",
"pageResolution": "directory",
"trailingSlash": "ignore",
"routes": [
{ "route": "/", "type": "page", "pattern": "/^\\/$/", "prerender": true },
{
"route": "/register",
"type": "page",
"pattern": "/^\\/register\\/?$/",
"prerender": false
},
{
"route": "/rss.xml",
"type": "endpoint",
"pattern": "/^\\/rss\\.xml$/",
"prerender": false
},
{
"route": "/about",
"type": "page",
"pattern": "/^\\/about\\/?$/",
"prerender": true
},
{
"route": "/blog",
"type": "page",
"pattern": "/^\\/blog\\/?$/",
"prerender": false
},
{
"route": "/blog/inset",
"type": "page",
"pattern": "/^\\/blog\\/inset\\/?$/",
"prerender": true
},
{
"route": "/blog/[...slug]",
"type": "page",
"pattern": "/^\\/blog(?:\\/(.*?))?\\/?$/",
"prerender": false
},
{
"route": "/404",
"type": "page",
"pattern": "/^\\/404\\/?$/",
"prerender": true
},
{
"route": "/old-blog",
"type": "redirect",
"pattern": "/^\\/old-blog\\/?$/",
"prerender": false,
"redirectPath": "/blog/"
},
{
"route": "/old-blog/[...slug]",
"type": "redirect",
"pattern": "/^\\/old-blog(?:\\/(.*?))?\\/?$/",
"prerender": false,
"redirectPath": "/blog/[...slug]"
}
]
}
}
|
Beta Was this translation helpful? Give feedback.
-
@lilnasy @natemoo-re Recommended I follow up here, rather than in a PR comment. @ottomated did this great PR, which would allow for page boolean exports. One thing worth considering, is allowing for object properties to be exportable, and not just booleans. This would allow for more advanced configurations such as ISR expiry time and other adapter specific configurations as mentioned above in the proposal. |
Beta Was this translation helpful? Give feedback.
-
Summary
Implement a page
config
object that can be exported, allowing for granular page specific adapter configuration. This opens up the ability to have edge, static, serverless, ISR and Netlify builders on a page by page basis.Background & Motivation
SvelteKit's Vercel adapter has a page
config
object that can be exported:The above example builds a specific page on Vercel as a Build Output API Prerender function with a
bypassToken
used for draft mode and on-demand ISR.Implementing a similar page
config
object (orAstro.locals.runtime.config({...})
in Astro that can be configured based on the installed adapter would open up so many possibilities for granular page control.Goals
Example
Vercel: Serverless (with ISR) page
Vercel: Edge page
Netlify: Builders page
These are obviously heavily inspired by SvelteKit's
config
object and just act as an initial discussion for further ideas 😄, how the config is implemented and its related properties could look quite different as a final result.Beta Was this translation helpful? Give feedback.
All reactions