Skip to content

Commit

Permalink
Use normalised uri for resolving SSG data routes
Browse files Browse the repository at this point in the history
  • Loading branch information
jvarho committed May 10, 2021
1 parent 5056766 commit 845b29b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/libs/core/src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ const normaliseDataUri = (uri: string, buildId: string) => {
.replace(/^(\/index)?$/, "/");
};

/*
* Get full data route uri from page name
*/
const fullDataUri = (uri: string, buildId: string) => {
const prefix = `/_next/data/${buildId}`;
if (uri === "/") {
return `${prefix}/index.js`;
}
return `${prefix}${uri}.json`;
};

/*
* Handles a data route
*/
Expand Down Expand Up @@ -44,12 +55,16 @@ export const handleDataReq = (
}
// TODO: this order reproduces default-handler logic,
// should sort all dynamic routes together in build
const dynamicSSG = matchDynamicSSG(uri, pages.ssg.dynamic, true);
const dynamicSSG = matchDynamicSSG(
fullDataUri(normalisedUri, buildId),
pages.ssg.dynamic,
true
);
if (dynamicSSG) {
return {
isData: true,
isStatic: true,
file: uri
file: fullDataUri(normalisedUri, buildId)
};
}
const dynamicSSR = matchDynamic(
Expand Down

0 comments on commit 845b29b

Please sign in to comment.