Skip to content

Commit

Permalink
commit some more suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah11918 committed Nov 26, 2024
1 parent 00cc1b0 commit 43d1364
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/content/docs/en/reference/api-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,21 @@ const socialImageURL = new URL('/images/preview.png', Astro.url);

`site` returns a `URL` made from `site` in your Astro config. It returns `undefined` if you have not set a value for [`site`](/en/reference/configuration-reference/#site) in your Astro config.

AN EXAMPLE WOULD BE NICE
```astro title="src/pages/index.astro" "Astro.site"
<link
rel="alternate"
type="application/rss+xml"
title="Your Site's Title"
href={new URL("rss.xml", Astro.site)}
/>
### `clientAddress`
<p>
**Type:** `string`<br />
<Since v="1.0.0" />
</p>
```astro title="src/pages/ip-address.astro" "Astro.clientAddress"
`clientAddress` specifies the [IP address](https://en.wikipedia.org/wiki/IP_address) of the request. This property is only available for routes rendered on demand and cannot be used on prerendered pages.
Expand All @@ -214,7 +220,7 @@ AN EXAMPLE WOULD BE NICE
---
export const prerender = false; // Not needed in 'server' mode
const ip = Astro.clientAddress;
---
```ts title="src/pages/ip-address.ts" "clientAddress"
<div>Your IP address is: <span class="address">{ ip }</span></div>
```
Expand Down Expand Up @@ -282,7 +288,7 @@ You can use this property to run conditional logic in middleware, for example, t
</Tabs>

### `request`

`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 the body of the request.
<p>

**Type:** `Request`
Expand Down Expand Up @@ -360,7 +366,7 @@ A page (and not a child component) must `return` the result of `Astro.redirect()

For statically-generated sites, this will produce a client redirect using a [`<meta http-equiv="refresh">` tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta#http-equiv) and does not support status codes.

When using an on-demand rendering mode, status codes are supported. Astro will serve redirected requests with a default HTTP response status of `302` unless another code is specified.
```astro title="src/pages/account.astro" {8} "Astro.redirect"
The following example redirects a user to a login page:
Expand All @@ -374,7 +380,7 @@ The following example redirects a user to a login page:
// If the user is not logged in, redirect them to the login page
if (!isLoggedIn(cookie)) {
return Astro.redirect('/login');
```ts "redirect"
}
---
```
Expand All @@ -401,14 +407,14 @@ The following example redirects a user to a login page:

`rewrite()` allows you to serve content from a different URL or path without redirecting the browser to a new page.

The method accepts either a string, a `URL`, or a `Request` for the location of the path.
```astro title="src/pages/index.astro" "Astro.rewrite"
Use a string to provide an explicit path:
<Tabs>
<TabItem label="Astro.rewrite()">
```astro title="src/pages/index.astro"
---
```ts "rewrite"
return Astro.rewrite("/login")
---
```
Expand Down

0 comments on commit 43d1364

Please sign in to comment.