Complete the code to render dynamic content on the server.
export async function get() {
const time = new Date().toLocaleTimeString();
return {
body: `Current time is: [1]`
};
}The variable time holds the formatted current time string, which is returned as dynamic content.
Complete the code to fetch data dynamically during server rendering.
export async function get() {
const response = await fetch('[1]');
const data = await response.json();
return {
body: JSON.stringify(data)
};
}Using a full URL like 'https://example.com/api/data' fetches dynamic data from an external API during SSR.
Fix the error in the server-side rendering function to correctly return dynamic props.
export async function get() {
const user = await fetchUser();
return {
[1]: { props: { user } }
};
}props instead of body in the return object.In Astro SSR, the get function should return an object with a body property containing the response data.
Fill both blanks to create a dynamic Astro component that fetches and displays user data.
--- const user = await fetchUser(); --- <h1>Hello, [1]!</h1> <p>Your email is [2].</p>
user.id or user.username instead of name or email.The component uses user.name for the greeting and user.email to show the email address dynamically.
Fill all three blanks to build a server-rendered Astro page that fetches posts and displays their titles.
---
const posts = await fetchPosts();
---
<ul>
{posts.map(post => (
<li key=[1]>[2]</li>
))}
</ul>
<p>Total posts: [3]</p>The list uses post.id as the key, displays post.title, and shows the total count with posts.length.
