You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/en/reference/api-reference.mdx
+55Lines changed: 55 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -165,6 +165,8 @@ See also: [`params`](#params)
165
165
166
166
### `Astro.request`
167
167
168
+
**Type:**`Request`
169
+
168
170
`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.
169
171
170
172
```astro
@@ -180,6 +182,7 @@ With the default `output: 'static'` option, `Astro.request.url` does not contain
`Astro.cookies` contains utilities for reading and manipulating cookies in [server-side rendering](/en/guides/server-side-rendering/) mode.
215
220
216
221
##### `get`
@@ -414,6 +419,8 @@ if (!isLoggedIn(cookie)) {
414
419
415
420
<p><Sincev="1.0.0-rc" /></p>
416
421
422
+
**Type:**`URL`
423
+
417
424
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.
418
425
419
426
Equivalent to doing `new URL(Astro.request.url)`.
@@ -441,6 +448,8 @@ const socialImageURL = new URL('/images/preview.png', Astro.url);
441
448
442
449
<p><Sincev="1.0.0-rc" /></p>
443
450
451
+
**Type:**`string`
452
+
444
453
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.
445
454
446
455
```astro
@@ -453,12 +462,16 @@ const ip = Astro.clientAddress;
453
462
454
463
### `Astro.site`
455
464
465
+
**Type:**`URL | undefined`
466
+
456
467
`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.
457
468
458
469
### `Astro.generator`
459
470
460
471
<p><Sincev="1.0.0" /></p>
461
472
473
+
**Type:**`string`
474
+
462
475
`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"`.
463
476
464
477
```astro mark="Astro.generator"
@@ -593,6 +606,8 @@ And would render HTML like this:
593
606
594
607
### `Astro.locals`
595
608
609
+
<p><Sincev="2.4.0" /></p>
610
+
596
611
`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.
`Astro.preferredLocale` is a computed value that represents the preferred locale of the user.
614
633
615
634
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
618
637
619
638
### `Astro.preferredLocaleList`
620
639
640
+
<p><Sincev="3.5.0" /></p>
641
+
642
+
**Type:**`string[] | undefined`
643
+
621
644
`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.
622
645
623
646
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
628
651
629
652
### `Astro.currentLocale`
630
653
654
+
<p><Sincev="3.5.6" /></p>
655
+
656
+
**Type:**`string | undefined`
657
+
631
658
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`.
632
659
633
660
## Endpoint Context
@@ -672,6 +699,8 @@ See also: [`params`](#params)
672
699
673
700
### `context.props`
674
701
702
+
<p><Sincev="1.5.0" /></p>
703
+
675
704
`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.
676
705
677
706
```ts title="src/pages/posts/[id].json.ts"
@@ -696,6 +725,8 @@ See also: [Data Passing with `props`](#data-passing-with-props)
696
725
697
726
### `context.request`
698
727
728
+
**Type:**`Request`
729
+
699
730
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.
700
731
701
732
```ts
@@ -710,18 +741,28 @@ See also: [Astro.request](#astrorequest)
710
741
711
742
### `context.cookies`
712
743
744
+
**Type:**`AstroCookies`
745
+
713
746
`context.cookies` contains utilities for reading and manipulating cookies.
714
747
715
748
See also: [Astro.cookies](#astrocookies)
716
749
717
750
### `context.url`
718
751
752
+
<p><Sincev="1.5.0" /></p>
753
+
754
+
**Type:**`URL`
755
+
719
756
A [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) object constructed from the current `context.request.url` URL string value.
720
757
721
758
See also: [Astro.url](#astrourl)
722
759
723
760
### `context.clientAddress`
724
761
762
+
<p><Sincev="1.5.0" /></p>
763
+
764
+
**Type:**`string`
765
+
725
766
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.
726
767
727
768
```ts
@@ -737,12 +778,20 @@ See also: [Astro.clientAddress](#astroclientaddress)
737
778
738
779
### `context.site`
739
780
781
+
<p><Sincev="1.5.0" /></p>
782
+
783
+
**Type:**`URL | undefined`
784
+
740
785
`context.site` returns a `URL` made from `site` in your Astro config. If undefined, this will return a URL generated from `localhost`.
741
786
742
787
See also: [Astro.site](#astrosite)
743
788
744
789
### `context.generator`
745
790
791
+
<p><Sincev="1.5.0" /></p>
792
+
793
+
**Type:**`string`
794
+
746
795
`context.generator` is a convenient way to indicate the version of Astro your project is running. It follows the format `"Astro v1.x.x"`.
747
796
748
797
```ts title="src/pages/site-info.json.ts"
@@ -758,6 +807,10 @@ See also: [Astro.generator](#astrogenerator)
`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.
762
815
763
816
```ts
@@ -772,6 +825,8 @@ See also: [`Astro.redirect()`](#astroredirect)
772
825
773
826
### `context.locals`
774
827
828
+
<p><Sincev="2.4.0" /></p>
829
+
775
830
`context.locals` is an object used to store and access arbitrary information during the lifecycle of a request.
776
831
777
832
Middleware functions can read and write the values of `context.locals`:
0 commit comments