-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
refactor(adapter-reference): improve adapter API docs #12673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
refactor(adapter-reference): improve adapter API docs #12673
Conversation
✅ Deploy Preview for astro-docs-2 ready!Built without sensitive environment variables
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
|
| export function createExports(manifest) { | ||
| const app = new App(manifest); | ||
| When this feature is enabled, Astro will return a map of the `Headers` emitted by the static pages. This map `experimentalRouteToHeaders` is available in the [`astro:build:generated` hook](/en/reference/integrations-reference/#astrobuildgenerated). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| When this feature is enabled, Astro will return a map of the `Headers` emitted by the static pages. This map `experimentalRouteToHeaders` is available in the [`astro:build:generated` hook](/en/reference/integrations-reference/#astrobuildgenerated). | |
| Defines if the adapter supports setting response headers for static pages. When this feature is enabled, Astro will return a map of the `Headers` emitted by the static pages. This map `experimentalRouteToHeaders` is available in the [`astro:build:generated` hook](/en/reference/integrations-reference/#astrobuildgenerated). The adapter could then use this to generate a `_headers` or other configuration file, for example. |
I'm not sure about the wording, but it would be good to specify what this is for, not just what it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like this?
| When this feature is enabled, Astro will return a map of the `Headers` emitted by the static pages. This map `experimentalRouteToHeaders` is available in the [`astro:build:generated` hook](/en/reference/integrations-reference/#astrobuildgenerated). | |
| Whether or not the adapter provides experimental support for setting response headers for static pages. When this feature is enabled, Astro will return a map of the `Headers` emitted by the static pages. This map `experimentalRouteToHeaders` is available in the [`astro:build:generated` hook](/en/reference/integrations-reference/#astrobuildgenerated) for generating files such as a `_headers` that allows you to make changes to the default HTTP header. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like Sarah's version but I'm not quite sure what _headers is. Reading Matt's suggestion I guess this is a configuration file so maybe we need to say it explicitly ("a _headers configuration file") to avoid confusion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why I said "generating files such as a _headers. Apparently, in some cases it's a .txt file, but e.g. saw for Cloudflare that someone needed to remove the file extension. What if we just remove the "a"?
"for generating files such as _headers ..."
I followed the trail to get from https://docs.netlify.com/manage/routing/headers/ to https://developer.mozilla.org/en-US/docs/Glossary/HTTP_header and even had a draft that included the purpose of the HTTP header file, but ultimately, it's not our job to go that far and document that basic, I think, for someone reading the Adapter API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I thought I had already answered, I probably forgot to click the button. 😅
Thanks for the extra context, I wasn't aware this was an "expected" file. So yes, this sounds good to me! (I think I prefer without a before, but I'm not a native speaker so choose the version that sounds the more correct to you!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, my wording was unclear! There was an implied [file] after "_headers". So to be explicit, it would be
The adapter could then use this to generate a `_headers` file or other configuration file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, not "a (_headers) or (other configuration file)", but "a (_headers or other configuration) file"!
Co-authored-by: Matt Kane <[email protected]>
Co-authored-by: Matt Kane <[email protected]>
florian-lefebvre
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! I always found our Adapter API docs a bit weak compared to the Integration API ones, love it!
| ``` | ||
|
|
||
| #### Start | ||
| The second argument passed to `createExports()` can be useful when you need to access build-time configuration in your server entrypoint. For example, your server entrypoint might need the directory path in the build output where the resources generated by Astro are located: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe link back to the args section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, good idea. I'm not sure how to integrate it in the current version, so maybe (while reusing Sarah's suggestion from the other place):
| The second argument passed to `createExports()` can be useful when you need to access build-time configuration in your server entrypoint. For example, your server entrypoint might need the directory path in the build output where the resources generated by Astro are located: | |
| You can access the [`args`](#args) defined by your adapter through the second argument of `createExports()`. This can be useful when you need to access build-time configuration in your server entrypoint. For example, your server might need to identify where assets generated by Astro are located: |
Edit: updated with Sarah's most recent suggestion
|
Re |
|
|
||
| A JSON-serializable value that will be passed to the adapter's server entrypoint at runtime. This is useful to pass an object containing build-time configuration (e.g. paths, secrets, etc.) to your server runtime code. | ||
|
|
||
| The following example defines an `args` object to pass to [the server entrypoint](#building-a-server-entrypoint) the directory path in the build output where the resources generated by Astro are located: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is something not quite grammatical about this. So I tried to figure out what this was saying. When you break it down, it says:
| The following example defines an `args` object to pass to [the server entrypoint](#building-a-server-entrypoint) the directory path in the build output where the resources generated by Astro are located: | |
| The following example defines an `args` object with the directory path in the build output for the location of the resources generated by Astro: |
Is config.build.assets a directory path? (it doesn't look like a path in the file tree/URL sense (`///), but I'm not familiar with this usage so it is probably fine. Just checking!)
It's also true that it's being passed to the server entry point, but a) you already defined args as something that gets passed to a server entry point and b) that makes this sentence more complicated to include the thing that you are passing and what you're passing it to. So, it's probably clearer not to mention that so that this can focus on helping make sense of what args is/does.
So, is the above correct? (Because that's what you've said.) If not, how does it need to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The args property was the hardest to understand (this is not the easiest word to look for in a codebase 😆), so this section may not be the most accurate.
Is config.build.assets a directory path?
I'm honestly not sure what is the actual value. Reading the configuration reference, that could be only the directory name. I don't know if there is some kind of internal resolution to turn it in a relative/absolute path.
So, your suggestion sounds good to me! I wasn't fan of my version but couldn't find a better wording. 😅
I'm not committing it yet in case someone else want to answer your question/if there is anything to improve regarding that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe @ascorbic or @florian-lefebvre can clarify what args is: a path? a directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically args can be anything (as long as it's serializable)! It's just data you want to get in createExports(), for example: https://github.com/withastro/astro/blob/7b7e037e435488227a361dcbe89a0a44d327c2c4/packages/integrations/node/src/server.ts#L16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "the directory path in the build output where the resources generated by Astro are located" is too confusing and shoulkd be removed. It's just an example of the sort of thing that could be passed in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The following example defines an `args` object to pass to [the server entrypoint](#building-a-server-entrypoint) the directory path in the build output where the resources generated by Astro are located: | |
| The following example defines an `args` object to identify where assets generated by Astro are located: |
Would this maybe be accurate and "good enough" then? Or
"... defines an args object to provide additional information about assets generated by Astro"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The following example defines an `args` object to pass to [the server entrypoint](#building-a-server-entrypoint) the directory path in the build output where the resources generated by Astro are located: | |
| The following example defines an `args` object with a property that identifies where assets generated by Astro are located: |
| ## Building a server entrypoint | ||
|
|
||
| ```js | ||
| Astro's adapter API attempts to work with any type of host, and gives a flexible way to conform to the host APIs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Astro's adapter API attempts to work with any type of host, and gives a flexible way to conform to the host APIs. | |
| You will need to create a file that executes during server-side requests to enable on-demand rendering with your particular host. Astro's adapter API attempts to work with any type of host, and gives a flexible way to conform to the host APIs. |
Feels like something like this is kind of needed here? I just took phrases from various places, so make this make sense 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyone? Suggestions for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I preferred to wait before committing it in case one of our adapter experts wanted to check the accuracy, but great idea! And this sounds correct to me.
Co-authored-by: Matt Kane <[email protected]> Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Armand Philippot <[email protected]>
|
I think everyone has done some amazing work supporting @ArmandPhilippot 's efforts! Only two points where I feel we really need to do a tiny bit better (called in both Matt and Florian to help), and once those feel good, this puppy LGTM! |
|
Thanks everyone for the really helpful feedbacks! ❤️ I added a new While doing so, I noticed we document the methods available from
We also have some static methods for
I'm not quite sure how to make the distinction between the static methods and the others with the current structure.
|
Description (required)
<Since />.createExports(): a second argument exists to retrieve data fromsetAdapter().astro/appAPIs:app.getAllowedDomains(),app.removeBase(),app.setCookieHeaders()app.match()type: a second argument exists.envGetSecretfrom "Adapter features" to "Astro features".h2.Exports>createExports()andStart>start()in "Build a server entrypoint" with some explanations about their shape.See the relevant links to check types/default/since:
experimentalStaticHeaders: added in feat(csp): add static header adapter function astro#13926AdapterSupportandAdapterSupportWithMessage: added in refactor: rework supportedAstroFeatures astro#11806suppressinAdapterSupportWithMessage: added in Add option to suppress adapter feature support log astro#13842previewEntrypoint: added in Node.js standalone mode + support for astro preview astro#5056client: added in Allow adapters to customize headers for fetch requests astro#14543adapterFeatures: added in feat: adapter features, deprecate astro configs astro#7839buildOutput: added in feat(hybrid): Clean logging and misc tweaks for hybrid removal astro#11942 (and feat: changesets for the hybrid removal astro#11941 for the changesets)supportedAstroFeatures: added in feat: astro features astro#7815envGetSecret: added in feat(astro): experimental astro:env astro#10974i18nDomains: added in feat(i18n): domain support astro#9143 (there was ani18nproperty before, but since this uses another name, this is "new")sharpImageService: added in refactor: rework supportedAstroFeatures astro#11806envGetSecretandi18nDomainswere added at the same time as the corresponding experimental feature, I'm not sure if we should use the stable release or not for them. Currently, I'm using the version of the experimental release.astro/apppublic APIs (only the missing ones):getAdapterLogger: added in refactor: use new Astro internals astro#8254 but I can't find it in the changelog... looking at the merge data, this was 2 days beforev3.0.0so I think it's fine to use this version.getAllowedDomains: added in withastro/astro@6ee63bf which matchesv5.14.2removeBase: add in Handlebasein adapters astro#5290setCookieHeaders: added in Astro.cookies implementation astro#4876setManifestData: added in refactor: use SSR manifest in dev astro#7587Room for improvement: except for
envGetSecretthat was already documented, theAstro featuressection is pretty succinct. I'm not sure how these features can/should be used, so I have not developed them.Not documented
app.setManifestDatais publicly available when creating a newApp(astro/app) but I couldn't find an usage in the source code so I wonder if this is a leftover that should be removed or something like that.Related issues & labels (optional)
add new content,consistency/formatting,improve or update documentation