Reputation: 1466
backend
laravel api and the frontend
for next.js/lib/axios.ts
fetcher
file in which you don't need to specify the absolute url path of your backend because it's already been configured in axiosgetStaticProps
inside my dashboard.tsx
page file and use fetcher I got this errorswr
by the way.Upvotes: 0
Views: 132
Reputation: 921
With getServerSideProps or getStaticProps you need to have absolute URL's.
You currently have
...('/api/dashboards') //This is not an absolute url
What you need is something like this
...('http://localhost:8000/api/dashboards') //or whatever port it is on.
Keep in mind when you push to staging or something like that the url will no longer be localhost
so you would be best to use a env file.
Final product would end up looking like this
...('${process.env.CURRENT_URL}/api/dashboards')
.env.development
CURRENT_URL=http://localhost:8000
.env.production
CURRENT_URL=https://example.com
Simple fetch
const response = await fetch('${process.env.NEXT_PUBLIC_BACKEND_URL}/api/dashboards')
const res = await response.json()
console.log(res)
Upvotes: 1