From 2f14de85454230d619a3759618110332780bb9f3 Mon Sep 17 00:00:00 2001 From: Aidan Hilt <11202897+AidanHilt@users.noreply.github.com> Date: Tue, 4 Mar 2025 00:07:03 -0500 Subject: [PATCH] fix: experimental basePath support PR bugs (#1409) * Bugfixes for the experimental basepath feature * Added a redirect to baseURL for the user context * Addressing PR comments * Reverting formatting changes to _app.tsx * Running pnpm format --- server/index.ts | 6 +++++- src/context/UserContext.tsx | 3 ++- src/pages/movie/[movieId]/index.tsx | 4 +++- src/pages/tv/[tvId]/index.tsx | 4 +++- src/utils/navigationUtil.ts | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/server/index.ts b/server/index.ts index 069ba606..1716495d 100644 --- a/server/index.ts +++ b/server/index.ts @@ -195,7 +195,11 @@ app }) ); const apiDocs = YAML.load(API_SPEC_PATH); - server.use('/api-docs', swaggerUi.serve, swaggerUi.setup(apiDocs)); + server.use( + `${process.env.NEXT_PUBLIC_BASE_PATH || ''}/api-docs`, + swaggerUi.serve, + swaggerUi.setup(apiDocs) + ); server.use( `${process.env.NEXT_PUBLIC_BASE_PATH || ''}`, OpenApiValidator.middleware({ diff --git a/src/context/UserContext.tsx b/src/context/UserContext.tsx index bd07989b..74838431 100644 --- a/src/context/UserContext.tsx +++ b/src/context/UserContext.tsx @@ -17,6 +17,7 @@ export const UserContext = ({ initialUser, children }: UserContextProps) => { const { user, error, revalidate } = useUser({ initialData: initialUser }); const router = useRouter(); const routing = useRef(false); + const API_BASE = process.env.NEXT_PUBLIC_BASE_PATH || ''; useEffect(() => { revalidate(); @@ -29,7 +30,7 @@ export const UserContext = ({ initialUser, children }: UserContextProps) => { !routing.current ) { routing.current = true; - location.href = '/login'; + location.href = `${API_BASE}/login`; } }, [router, user, error]); diff --git a/src/pages/movie/[movieId]/index.tsx b/src/pages/movie/[movieId]/index.tsx index d9788a20..1de3874e 100644 --- a/src/pages/movie/[movieId]/index.tsx +++ b/src/pages/movie/[movieId]/index.tsx @@ -11,13 +11,15 @@ const MoviePage: NextPage = ({ movie }) => { return ; }; +const API_BASE = process.env.NEXT_PUBLIC_BASE_PATH || ''; + export const getServerSideProps: GetServerSideProps = async ( ctx ) => { const response = await axios.get( `http://${process.env.HOST || 'localhost'}:${ process.env.PORT || 5055 - }/api/v1/movie/${ctx.query.movieId}`, + }${API_BASE}/api/v1/movie/${ctx.query.movieId}`, { headers: ctx.req?.headers?.cookie ? { cookie: ctx.req.headers.cookie } diff --git a/src/pages/tv/[tvId]/index.tsx b/src/pages/tv/[tvId]/index.tsx index 9659d82c..da4bb8fe 100644 --- a/src/pages/tv/[tvId]/index.tsx +++ b/src/pages/tv/[tvId]/index.tsx @@ -11,13 +11,15 @@ const TvPage: NextPage = ({ tv }) => { return ; }; +const API_BASE = process.env.NEXT_PUBLIC_BASE_PATH || ''; + export const getServerSideProps: GetServerSideProps = async ( ctx ) => { const response = await axios.get( `http://${process.env.HOST || 'localhost'}:${ process.env.PORT || 5055 - }/api/v1/tv/${ctx.query.tvId}`, + }${API_BASE}/api/v1/tv/${ctx.query.tvId}`, { headers: ctx.req?.headers?.cookie ? { cookie: ctx.req.headers.cookie } diff --git a/src/utils/navigationUtil.ts b/src/utils/navigationUtil.ts index 1dddcf92..ef2908b0 100644 --- a/src/utils/navigationUtil.ts +++ b/src/utils/navigationUtil.ts @@ -1,4 +1,4 @@ export const getBasedPath = (path: string) => { const API_BASE = process.env.NEXT_PUBLIC_BASE_PATH || ''; - return path.startsWith('/') ? `${API_BASE}${path}` : path; + return path.startsWith('/') && path !== '/' ? `${API_BASE}${path}` : path; };