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
This commit is contained in:
@@ -207,7 +207,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({
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
@@ -10,11 +10,13 @@ const MoviePage: NextPage<MoviePageProps> = ({ movie }) => {
|
||||
return <MovieDetails movie={movie} />;
|
||||
};
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_BASE_PATH || '';
|
||||
|
||||
export const getServerSideProps: GetServerSideProps<MoviePageProps> = async (
|
||||
ctx
|
||||
) => {
|
||||
const res = await fetch(
|
||||
`http://localhost:${process.env.PORT || 5055}/api/v1/movie/${
|
||||
`http://localhost:${process.env.PORT || 5055}${API_BASE}/api/v1/movie/${
|
||||
ctx.query.movieId
|
||||
}`,
|
||||
{
|
||||
|
||||
@@ -10,11 +10,15 @@ const TvPage: NextPage<TvPageProps> = ({ tv }) => {
|
||||
return <TvDetails tv={tv} />;
|
||||
};
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_BASE_PATH || '';
|
||||
|
||||
export const getServerSideProps: GetServerSideProps<TvPageProps> = async (
|
||||
ctx
|
||||
) => {
|
||||
const res = await fetch(
|
||||
`http://localhost:${process.env.PORT || 5055}/api/v1/tv/${ctx.query.tvId}`,
|
||||
`http://localhost:${process.env.PORT || 5055}${API_BASE}/api/v1/tv/${
|
||||
ctx.query.tvId
|
||||
}`,
|
||||
{
|
||||
headers: ctx.req?.headers?.cookie
|
||||
? { cookie: ctx.req.headers.cookie }
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user