diff --git a/server/index.ts b/server/index.ts index 069ba6060..1716495d3 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 bd07989b5..74838431d 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 d9788a202..1de3874e0 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 9659d82ca..da4bb8feb 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 1dddcf921..ef2908b06 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; };