Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Example] Use getServerSideProps in api-routes #11057

Merged
merged 1 commit into from Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/api-routes/pages/index.js
Expand Up @@ -9,7 +9,7 @@ const Index = ({ people }) => (
</ul>
)

export async function getStaticProps() {
export async function getServerSideProps() {
const response = await fetch('http://localhost:3000/api/people')
const people = await response.json()

Expand Down
15 changes: 1 addition & 14 deletions examples/api-routes/pages/person/[id].js
Expand Up @@ -30,20 +30,7 @@ const Person = ({ data, status }) =>
<p>{data.message}</p>
)

export async function getStaticPaths() {
const response = await fetch('http://localhost:3000/api/people')
const data = await response.json()

const paths = data.map(person => ({
params: {
id: person.id,
},
}))

return { paths, fallback: false }
}

export async function getStaticProps({ params }) {
export async function getServerSideProps({ params }) {
const response = await fetch(`http://localhost:3000/api/people/${params.id}`)
const data = await response.json()

Expand Down