Skip to content

Commit

Permalink
Fix routing breaking when in active mode
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding authored and DavieReid committed Dec 7, 2023
1 parent 9629808 commit ef29bbf
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/site-middleware/src/withMDXContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ function stripParams(resolvedUrl: string) {
}

function normalizeUrl(url: string) {
const pathname = stripParams(url);
return /\/index$/.test(pathname) ? `${pathname}.mdx` : pathname;
return /\/index$/.test(url) ? `${url}.mdx` : url;
}

async function loadSnapshotFile(url) {
Expand Down Expand Up @@ -90,19 +89,20 @@ export const withMDXContent: MosaicMiddleware<ContentProps> = async (
const { resolvedUrl } = context;
const mosaicMode = context.res.getHeader('X-Mosaic-Mode' || 'active') as MosaicMode;
const extname = path.extname(resolvedUrl);
const pathname = stripParams(resolvedUrl);
// Any urls which are not prefixed, will default to MDX
const isMDX = extname === '.mdx' || extname === '';
if (!isMDX) {
return {};
}
let text;
if (mosaicMode === 'snapshot-file') {
text = await loadSnapshotFile(resolvedUrl);
text = await loadSnapshotFile(pathname);
} else if (mosaicMode === 'snapshot-s3') {
text = await loadSnapshotS3(resolvedUrl);
text = await loadSnapshotS3(pathname);
} else {
const mosaicUrl = context.res.getHeader('X-Mosaic-Content-Url');
const fetchedResult = await loadActiveContent(`${mosaicUrl}${resolvedUrl}`);
const fetchedResult = await loadActiveContent(`${mosaicUrl}${pathname}`);
const isRedirect = typeof fetchedResult === 'object';
if (isRedirect) {
return fetchedResult;
Expand Down

1 comment on commit ef29bbf

@vercel
Copy link

@vercel vercel bot commented on ef29bbf Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

mosaic – ./

mosaic-mosaic-dev-team.vercel.app
mosaic-git-main-mosaic-dev-team.vercel.app

Please sign in to comment.