strapi / strapi-starter-next-corporate

Next.js starter for creating a corporate site with Strapi.
https://strapi-starter-next-corporate.vercel.app
MIT License
346 stars 95 forks source link

Error 404 with predefined SSR path #65

Closed eahmann closed 3 years ago

eahmann commented 3 years ago

I'm trying to add a new set of SSR pages alongside the SSG pages provided by the starter. From a fresh starter install, a basic example is to add test/index.js to pages.

// test/index.js
const Test = ({ data }) => {

  return (
    <div>
     <pre>{JSON.stringify(data, null, 2)}</pre>
    </div>
  )
}

export async function getServerSideProps() {
  const res = await fetch(`http://localhost:1337/pages/1`)
  const data = await res.json()

  return { props: { data } }
}
export default Test

Then configure a button to /test url. This will result in a 404 error. In development you can refresh to see the desired page at /test or directly navigate to the page. When deployed /test is always 404. I don't know if this is a Next.js issue or if has to do with how the starter is configured. Any help would be greatly appreciated. Thank you

eahmann commented 3 years ago

Well of course localhost doesn't work in production. fetchAPI('/pages/1') is what I needed.