Server Error
FetchError: invalid json response body at localhost:3000/components/json/whoToFollow.json reason: Unexpected token < in JSON at position 0
// components/config/index.js
const dev = process.env.NODE_ENV !== 'production';
export const server = dev ? 'http://localhost:3000' : 'https://your_deployment.server.com';
// pages/[id].js
import { server } from '../config';
// ...
function PostPage({ followResults, providers }) {
// ...
}
export async function getServerSideProps(context) {
const followResults = await fetch(`${server}/components/json/whoToFollow.json`).then(
(res) => res.json()
);
const providers = await getProviders();
const session = await getSession(context);
return {
props: {
followResults,
providers,
session,
},
};
}
// whoToFollow.json
[
{
"userImg":"../Widgets/img/spacex.jpg",
"username":"SpaceX",
"tag":"@SpaceX"
},
{
"userImg":"../Widgets/img/musk.jpg",
"username":"Elon Musk",
"tag":"@elonmusk"
},
{
"userImg":"../Widgets/img/tesla.jpg",
"username":"Tesla",
"tag":"@Tesla"
}
]