Skip to content

fix: correctly rewrite default locale ISR homepage to ODB handler #1757

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

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
81ce185
fix: redirect isr index pages without a sub path
orinokai Nov 10, 2022
1dd7c26
test: update homepage to test isr i18n
orinokai Nov 10, 2022
6bdee93
Merge branch 'main' into rs/isr-i18n-homepage
orinokai Nov 18, 2022
932eaab
Merge branch 'main' into rs/isr-i18n-homepage
orinokai Nov 21, 2022
ab4596b
feat: proxy tv maze api
orinokai Dec 5, 2022
c0fdadd
Merge branch 'main' into rs/isr-i18n-homepage
orinokai Dec 5, 2022
a44815c
Merge branch 'main' into rs/isr-i18n-homepage
orinokai Dec 7, 2022
fe332e6
Merge branch 'main' into rs/isr-i18n-homepage
orinokai Dec 8, 2022
2aa02db
fix: use static 404 for non-prerendered dynamic routes without fallba…
orinokai Dec 9, 2022
5f7f4ba
chore(deps): update dependency sass to v1.56.2 (#1837)
renovate[bot] Dec 12, 2022
9aa4c38
chore(deps): update dependency typescript to v4.9.4 (#1838)
renovate[bot] Dec 12, 2022
a5b8047
fix: support appDir (#1638)
ascorbic Dec 12, 2022
850a203
chore(deps): update dependency @netlify/build to v29 (#1832)
renovate[bot] Dec 16, 2022
6479e70
chore(deps): update nextjs monorepo (#1842)
renovate[bot] Dec 19, 2022
2539d24
fix(deps): update dependency destr to v1.2.2 (#1843)
renovate[bot] Dec 19, 2022
1bfabc3
chore(deps): update dependency @netlify/build to ^29.1.3 (#1845)
renovate[bot] Dec 19, 2022
ec95bba
chore: release main (#1835)
token-generator-app[bot] Dec 19, 2022
15279a2
chore(deps): update dependency @netlify/build to ^29.2.1 (#1848)
renovate[bot] Dec 20, 2022
254a9ab
chore(deps): update dependency @netlify/build to ^29.2.2 (#1853)
renovate[bot] Dec 21, 2022
28ea00e
test: re-enable unit tests (#1852)
ascorbic Dec 22, 2022
d4ff894
fix: serve static files from basePath (#1850)
ascorbic Dec 22, 2022
686ac61
chore: update next to 13.0.7 (#1840)
orinokai Dec 22, 2022
53ecc31
chore(deps): update dependency @netlify/build to ^29.3.0 (#1856)
renovate[bot] Dec 22, 2022
2d3eb65
chore(deps): update dependency @babel/core to v7.20.7 (#1858)
renovate[bot] Dec 26, 2022
c929816
fix(deps): update dependency moize to v6.1.4 (#1859)
renovate[bot] Dec 26, 2022
af2a3e0
fix(deps): update dependency regenerator-runtime to v0.13.11 (#1860)
renovate[bot] Jan 2, 2023
05ae395
chore(deps): update dependency @netlify/build to ^29.4.0 (#1862)
renovate[bot] Jan 3, 2023
3f62a61
fix: redirect isr index pages without a sub path
orinokai Nov 10, 2022
7da0835
test: update homepage to test isr i18n
orinokai Nov 10, 2022
1140bc8
feat: proxy tv maze api
orinokai Dec 5, 2022
532d38d
Merge branch 'rs/isr-i18n-homepage' of github.com:netlify/netlify-plu…
orinokai Jan 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demos/default/pages/api/shows/[...params].js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default async (req, res) => {
const id = params[0]

// Get the data
const fetchRes = await fetch(`https://api.tvmaze.com/shows/${id}`)
const fetchRes = await fetch(`https://tvproxy.netlify.app/shows/${id}`)
const data = await fetchRes.json()

// If show was found, return it
Expand Down
2 changes: 1 addition & 1 deletion demos/default/pages/api/shows/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default async (req, res) => {
const { id } = query

// Get the data
const fetchRes = await fetch(`https://api.tvmaze.com/shows/${id}`)
const fetchRes = await fetch(`https://tvproxy.netlify.app/shows/${id}`)
const data = await fetchRes.json()

// If show was found, return it
Expand Down
2 changes: 1 addition & 1 deletion demos/default/pages/deep/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Show = ({ show }) => (
)

export const getServerSideProps = async ({ params }) => {
const res = await fetch('https://api.tvmaze.com/shows/42')
const res = await fetch('https://tvproxy.netlify.app/shows/42')
const data = await res.json()

return {
Expand Down
2 changes: 1 addition & 1 deletion demos/default/pages/getServerSideProps/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const getServerSideProps = async ({ params }) => {
// The ID to render
const { id } = params

const res = await fetch(`https://api.tvmaze.com/shows/${id}`)
const res = await fetch(`https://tvproxy.netlify.app/shows/${id}`)
const data = await res.json()

// Set error code if show item could not be found
Expand Down
2 changes: 1 addition & 1 deletion demos/default/pages/getServerSideProps/all/[[...slug]].js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const getServerSideProps = async ({ params }) => {
// The ID to render
const { slug } = params

const res = await fetch(`https://api.tvmaze.com/shows/${slug[0]}`)
const res = await fetch(`https://tvproxy.netlify.app/shows/${slug[0]}`)
const data = await res.json()

// Set error code if show item could not be found
Expand Down
2 changes: 1 addition & 1 deletion demos/default/pages/getServerSideProps/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Show = ({ show }) => (
)

export const getServerSideProps = async ({ params }) => {
const res = await fetch('https://api.tvmaze.com/shows/42')
const res = await fetch('https://tvproxy.netlify.app/shows/42')
const data = await res.json()

return {
Expand Down
2 changes: 1 addition & 1 deletion demos/default/pages/getStaticProps/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function getStaticProps({ params }) {
// The ID to render
const { id } = params

const res = await fetch(`https://api.tvmaze.com/shows/${id}`)
const res = await fetch(`https://tvproxy.netlify.app/shows/${id}`)
const data = await res.json()
const time = new Date().toLocaleTimeString()

Expand Down
2 changes: 1 addition & 1 deletion demos/default/pages/getStaticProps/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Show = ({ show }) => (
)

export async function getStaticProps(context) {
const res = await fetch(`https://api.tvmaze.com/shows/71`)
const res = await fetch(`https://tvproxy.netlify.app/shows/71`)
const data = await res.json()

return {
Expand Down
2 changes: 1 addition & 1 deletion demos/default/pages/getStaticProps/with-revalidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Show = ({ show }) => (
)

export async function getStaticProps(context) {
const res = await fetch(`https://api.tvmaze.com/shows/71`)
const res = await fetch(`https://tvproxy.netlify.app/shows/71`)
const data = await res.json()

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export async function getStaticProps({ params }) {
const { slug } = params
const id = slug[slug.length - 1]

const res = await fetch(`https://api.tvmaze.com/shows/${id}`)
const res = await fetch(`https://tvproxy.netlify.app/shows/${id}`)
const data = await res.json()
const time = new Date().toLocaleTimeString()

Expand Down
2 changes: 1 addition & 1 deletion demos/default/pages/getStaticProps/withFallback/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function getStaticProps({ params }) {
// The ID to render
const { id } = params

const res = await fetch(`https://api.tvmaze.com/shows/${id}`)
const res = await fetch(`https://tvproxy.netlify.app/shows/${id}`)
const data = await res.json()
const time = new Date().toLocaleTimeString()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function getStaticProps({ params }) {
// The ID to render
const { id } = params

const res = await fetch(`https://api.tvmaze.com/shows/${id}`)
const res = await fetch(`https://tvproxy.netlify.app/shows/${id}`)
const data = await res.json()
const time = new Date().toLocaleTimeString()

Expand Down
2 changes: 1 addition & 1 deletion demos/default/pages/getStaticProps/withRevalidate/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function getStaticProps({ params }) {
// The ID to render
const { id } = params

const res = await fetch(`https://api.tvmaze.com/shows/${id}`)
const res = await fetch(`https://tvproxy.netlify.app/shows/${id}`)
const data = await res.json()
const time = new Date().toLocaleTimeString()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export async function getStaticProps({ params }) {
// The ID to render
const { id } = params

const res = await fetch(`https://api.tvmaze.com/shows/${id}`)
const res = await fetch(`https://tvproxy.netlify.app/shows/${id}`)
const data = await res.json()
const time = new Date().toLocaleTimeString()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function getStaticProps({ params }) {
// The ID to render
const { id } = params

const res = await fetch(`https://api.tvmaze.com/shows/${id}`)
const res = await fetch(`https://tvproxy.netlify.app/shows/${id}`)
const data = await res.json()
const time = new Date().toLocaleTimeString()

Expand Down
23 changes: 15 additions & 8 deletions demos/default/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ const Index = ({ shows, nodeEnv }) => {
<div>
<Header />

<p>This is a demo of a NextJS application with Server-Side Rendering (SSR).</p>
<p>This is a demo of a NextJS application with Incremental Static Regeneration (ISR).</p>

<h2>Server-Side Rendering</h2>
<h2>Incremental Static Regeneration</h2>

<p>
This page is server-side rendered. It fetches a random list of five TV shows from the TVmaze REST API. Refresh
this page to see it change.
This page is rendered by an On-Demand Builder (ODB) function. It fetches a random list of five TV shows from
the TVmaze REST API. After 60 seconds, the ODB cache is invalidated and the page will be re-rendered on the
next request.
</p>
<code>NODE_ENV: {nodeEnv}</code>

Expand Down Expand Up @@ -176,21 +177,27 @@ const Index = ({ shows, nodeEnv }) => {
)
}

Index.getInitialProps = async function () {
export async function getStaticProps(context) {
const dev = process.env.CONTEXT !== 'production'

// Set a random page between 1 and 100
const randomPage = Math.floor(Math.random() * 100) + 1
// FIXME: stub out in dev
const server = dev
? `https://api.tvmaze.com/shows?page=${randomPage}`
: `https://api.tvmaze.com/shows?page=${randomPage}`
? `https://tvproxy.netlify.app/shows/page/${randomPage}`
: `https://tvproxy.netlify.app/shows/page/${randomPage}`

// Get the data
const res = await fetch(server)
const data = await res.json()

return { shows: data.slice(0, 5), nodeEnv: process.env.NODE_ENV || null }
return {
props: {
shows: data.slice(0, 5),
nodeEnv: process.env.NODE_ENV || null,
},
revalidate: 60,
}
}

export default Index
2 changes: 1 addition & 1 deletion demos/default/pages/shows/[...params].js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ CatchAll.getInitialProps = async ({ res: req, query }) => {
const id = params[0]

// Get the data
const res = await fetch(`https://api.tvmaze.com/shows/${id}`)
const res = await fetch(`https://tvproxy.netlify.app/shows/${id}`)
const data = await res.json()

// Set error code if show item could not be found
Expand Down
2 changes: 1 addition & 1 deletion demos/default/pages/shows/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Show.getInitialProps = async ({ res: req, query }) => {
const { id } = query

// Get the data
const res = await fetch(`https://api.tvmaze.com/shows/${id}`)
const res = await fetch(`https://tvproxy.netlify.app/shows/${id}`)
const data = await res.json()

// Set error code if show item could not be found
Expand Down
Loading