Skip to content

Commit

Permalink
fix: corrected initial fallback data load on details page (#3395)
Browse files Browse the repository at this point in the history
  • Loading branch information
OwsleyJr committed May 11, 2023
1 parent c1e1033 commit 4bd8764
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
36 changes: 18 additions & 18 deletions src/pages/movie/[movieId]/index.tsx
@@ -1,7 +1,7 @@
import MovieDetails from '@app/components/MovieDetails';
import type { MovieDetails as MovieDetailsType } from '@server/models/Movie';
import axios from 'axios';
import type { NextPage } from 'next';
import type { GetServerSideProps, NextPage } from 'next';

interface MoviePageProps {
movie?: MovieDetailsType;
Expand All @@ -11,25 +11,25 @@ const MoviePage: NextPage<MoviePageProps> = ({ movie }) => {
return <MovieDetails movie={movie} />;
};

MoviePage.getInitialProps = async (ctx) => {
if (ctx.req) {
const response = await axios.get<MovieDetailsType>(
`http://localhost:${process.env.PORT || 5055}/api/v1/movie/${
ctx.query.movieId
}`,
{
headers: ctx.req?.headers?.cookie
? { cookie: ctx.req.headers.cookie }
: undefined,
}
);
export const getServerSideProps: GetServerSideProps<MoviePageProps> = async (
ctx
) => {
const response = await axios.get<MovieDetailsType>(
`http://localhost:${process.env.PORT || 5055}/api/v1/movie/${
ctx.query.movieId
}`,
{
headers: ctx.req?.headers?.cookie
? { cookie: ctx.req.headers.cookie }
: undefined,
}
);

return {
return {
props: {
movie: response.data,
};
}

return {};
},
};
};

export default MoviePage;
34 changes: 16 additions & 18 deletions src/pages/tv/[tvId]/index.tsx
@@ -1,7 +1,7 @@
import TvDetails from '@app/components/TvDetails';
import type { TvDetails as TvDetailsType } from '@server/models/Tv';
import axios from 'axios';
import type { NextPage } from 'next';
import type { GetServerSideProps, NextPage } from 'next';

interface TvPageProps {
tv?: TvDetailsType;
Expand All @@ -11,25 +11,23 @@ const TvPage: NextPage<TvPageProps> = ({ tv }) => {
return <TvDetails tv={tv} />;
};

TvPage.getInitialProps = async (ctx) => {
if (ctx.req) {
const response = await axios.get<TvDetailsType>(
`http://localhost:${process.env.PORT || 5055}/api/v1/tv/${
ctx.query.tvId
}`,
{
headers: ctx.req?.headers?.cookie
? { cookie: ctx.req.headers.cookie }
: undefined,
}
);
export const getServerSideProps: GetServerSideProps<TvPageProps> = async (
ctx
) => {
const response = await axios.get<TvDetailsType>(
`http://localhost:${process.env.PORT || 5055}/api/v1/tv/${ctx.query.tvId}`,
{
headers: ctx.req?.headers?.cookie
? { cookie: ctx.req.headers.cookie }
: undefined,
}
);

return {
return {
props: {
tv: response.data,
};
}

return {};
},
};
};

export default TvPage;

0 comments on commit 4bd8764

Please sign in to comment.