mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
34 lines
679 B
JavaScript
34 lines
679 B
JavaScript
export default function StaticPage({ data }) {
|
|
return <div id="username">{data.from}</div>
|
|
}
|
|
|
|
const port = process.env.NEXT_PUBLIC_API_PORT
|
|
|
|
export async function getStaticPaths() {
|
|
const res = await fetch(`http://localhost:${port}/usernames`)
|
|
const { usernames } = await res.json()
|
|
|
|
return {
|
|
fallback: false,
|
|
paths: usernames.map((username) => {
|
|
return {
|
|
params: {
|
|
username,
|
|
},
|
|
}
|
|
}),
|
|
}
|
|
}
|
|
|
|
export async function getStaticProps({ params }) {
|
|
const res = await fetch(
|
|
`http://localhost:${port}/usernames/${params.username}`
|
|
)
|
|
const json = await res.json()
|
|
return {
|
|
props: {
|
|
data: json,
|
|
},
|
|
}
|
|
}
|