Skip to content

Commit d6b50e1

Browse files
fix(api-reference): add missing Since/Type in Astro global & APIContext
* See withastro/astro#4986 for `site`, `generator`, `url`, `clientAddress`, `props` and `redirect` * See withastro/astro#6721 for `locals` * See withastro/astro#9021 for `preferredLocale` and `preferredLocaleList` * See withastro/astro#9101 for `currentLocale`
1 parent 3c7d574 commit d6b50e1

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/content/docs/en/reference/api-reference.mdx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ See also: [`params`](#params)
165165

166166
### `Astro.request`
167167

168+
**Type:** `Request`
169+
168170
`Astro.request` is a standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object. It can be used to get the `url`, `headers`, `method`, and even body of the request.
169171

170172
```astro
@@ -180,6 +182,7 @@ With the default `output: 'static'` option, `Astro.request.url` does not contain
180182

181183
### `Astro.response`
182184

185+
**Type:** `ResponseInit & { readonly headers: Headers }`
183186

184187
`Astro.response` is a standard `ResponseInit` object. It has the following structure.
185188

@@ -211,6 +214,8 @@ Astro.response.headers.set('Set-Cookie', 'a=b; Path=/;');
211214

212215
<p><Since v="1.4.0" /></p>
213216

217+
**Type:** `AstroCookies`
218+
214219
`Astro.cookies` contains utilities for reading and manipulating cookies in [server-side rendering](/en/guides/server-side-rendering/) mode.
215220

216221
##### `get`
@@ -414,6 +419,8 @@ if (!isLoggedIn(cookie)) {
414419

415420
<p><Since v="1.0.0-rc" /></p>
416421

422+
**Type:** `URL`
423+
417424
A [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) object constructed from the current `Astro.request.url` URL string value. Useful for interacting with individual properties of the request URL, like pathname and origin.
418425

419426
Equivalent to doing `new URL(Astro.request.url)`.
@@ -441,6 +448,8 @@ const socialImageURL = new URL('/images/preview.png', Astro.url);
441448

442449
<p><Since v="1.0.0-rc" /></p>
443450

451+
**Type:** `string`
452+
444453
Specifies the [IP address](https://en.wikipedia.org/wiki/IP_address) of the request. This property is only available when building for SSR (server-side rendering) and should not be used for static sites.
445454

446455
```astro
@@ -453,12 +462,16 @@ const ip = Astro.clientAddress;
453462

454463
### `Astro.site`
455464

465+
**Type:** `URL | undefined`
466+
456467
`Astro.site` returns a `URL` made from `site` in your Astro config. If `site` in your Astro config isn't defined, `Astro.site` won't be defined.
457468

458469
### `Astro.generator`
459470

460471
<p><Since v="1.0.0" /></p>
461472

473+
**Type:** `string`
474+
462475
`Astro.generator` is a convenient way to add a [`<meta name="generator">`](https://html.spec.whatwg.org/multipage/semantics.html#meta-generator) tag with your current version of Astro. It follows the format `"Astro v1.x.x"`.
463476

464477
```astro mark="Astro.generator"
@@ -593,6 +606,8 @@ And would render HTML like this:
593606

594607
### `Astro.locals`
595608

609+
<p><Since v="2.4.0" /></p>
610+
596611
`Astro.locals` is an object containing any values from the [`context.locals`](#contextlocals) object from a middleware. Use this to access data returned by middleware in your `.astro` files.
597612

598613
```astro title="src/pages/Orders.astro"
@@ -610,6 +625,10 @@ const orders = Array.from(Astro.locals.orders.entries());
610625

611626
### `Astro.preferredLocale`
612627

628+
<p><Since v="3.5.0" /></p>
629+
630+
**Type:** `string | undefined`
631+
613632
`Astro.preferredLocale` is a computed value that represents the preferred locale of the user.
614633

615634
It is computed by checking the configured locales in your `i18n.locales` array and locales supported by the users's browser via the header `Accept-Language`. This value is `undefined` if no such match exists.
@@ -618,6 +637,10 @@ This property is only available when building for SSR (server-side rendering) an
618637

619638
### `Astro.preferredLocaleList`
620639

640+
<p><Since v="3.5.0" /></p>
641+
642+
**Type:** `string[] | undefined`
643+
621644
`Astro.preferredLocaleList` represents the array of all locales that are both requested by the browser and supported by your website. This produces a list of all compatible languages between your site and your visitor.
622645

623646
If none of the browser's requested languages are found in your locales array, then the value is `[]`: you do not support any of your visitor's preferred locales.
@@ -628,6 +651,10 @@ This property is only available when building for SSR (server-side rendering) an
628651

629652
### `Astro.currentLocale`
630653

654+
<p><Since v="3.5.6" /></p>
655+
656+
**Type:** `string | undefined`
657+
631658
The locale computed from the current URL, using the syntax specified in your `locales` configuration. If the URL does not contain a `/[locale]/` prefix, then the value will default to `i18n.defaultLocale`.
632659

633660
## Endpoint Context
@@ -672,6 +699,8 @@ See also: [`params`](#params)
672699

673700
### `context.props`
674701

702+
<p><Since v="1.5.0" /></p>
703+
675704
`context.props` is an object containing any `props` passed from `getStaticPaths()`. Because `getStaticPaths()` is not used when building for SSR (server-side rendering), `context.props` is only available in static builds.
676705

677706
```ts title="src/pages/posts/[id].json.ts"
@@ -696,6 +725,8 @@ See also: [Data Passing with `props`](#data-passing-with-props)
696725

697726
### `context.request`
698727

728+
**Type:** `Request`
729+
699730
A standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object. It can be used to get the `url`, `headers`, `method`, and even body of the request.
700731

701732
```ts
@@ -710,18 +741,28 @@ See also: [Astro.request](#astrorequest)
710741

711742
### `context.cookies`
712743

744+
**Type:** `AstroCookies`
745+
713746
`context.cookies` contains utilities for reading and manipulating cookies.
714747

715748
See also: [Astro.cookies](#astrocookies)
716749

717750
### `context.url`
718751

752+
<p><Since v="1.5.0" /></p>
753+
754+
**Type:** `URL`
755+
719756
A [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) object constructed from the current `context.request.url` URL string value.
720757

721758
See also: [Astro.url](#astrourl)
722759

723760
### `context.clientAddress`
724761

762+
<p><Since v="1.5.0" /></p>
763+
764+
**Type:** `string`
765+
725766
Specifies the [IP address](https://en.wikipedia.org/wiki/IP_address) of the request. This property is only available when building for SSR (server-side rendering) and should not be used for static sites.
726767

727768
```ts
@@ -737,12 +778,20 @@ See also: [Astro.clientAddress](#astroclientaddress)
737778

738779
### `context.site`
739780

781+
<p><Since v="1.5.0" /></p>
782+
783+
**Type:** `URL | undefined`
784+
740785
`context.site` returns a `URL` made from `site` in your Astro config. If undefined, this will return a URL generated from `localhost`.
741786

742787
See also: [Astro.site](#astrosite)
743788

744789
### `context.generator`
745790

791+
<p><Since v="1.5.0" /></p>
792+
793+
**Type:** `string`
794+
746795
`context.generator` is a convenient way to indicate the version of Astro your project is running. It follows the format `"Astro v1.x.x"`.
747796

748797
```ts title="src/pages/site-info.json.ts"
@@ -758,6 +807,10 @@ See also: [Astro.generator](#astrogenerator)
758807

759808
### `context.redirect()`
760809

810+
<p><Since v="1.5.0" /></p>
811+
812+
**Type:** `(path: string, status?: number) => Response`
813+
761814
`context.redirect()` returns a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) object that allows you to redirect to another page. This function is only available when building for SSR (server-side rendering) and should not be used for static sites.
762815

763816
```ts
@@ -772,6 +825,8 @@ See also: [`Astro.redirect()`](#astroredirect)
772825

773826
### `context.locals`
774827

828+
<p><Since v="2.4.0" /></p>
829+
775830
`context.locals` is an object used to store and access arbitrary information during the lifecycle of a request.
776831

777832
Middleware functions can read and write the values of `context.locals`:

0 commit comments

Comments
 (0)