Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit 9de7963

Browse files
committed
fix: add json files
1 parent 8bb8ec7 commit 9de7963

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/pages/getStaticPropsWithRevalidate/setup.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ const setup = (functionsPath) => {
3636
inputPath: htmlPath,
3737
publishPath: functionDirectory,
3838
});
39+
const jsonPath = getFilePathForRoute(route, "json");
40+
setupStaticFileForPage({
41+
inputPath: jsonPath,
42+
publishPath: functionDirectory,
43+
});
3944

4045
filePathsDone.push(filePath);
4146
});

lib/templates/netlifyFunction.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@ exports.handler = async (event, context, callback) => {
3737
try {
3838
// remove first /
3939
const filepath = event.path === "/" ? "index" : event.path.slice(1);
40-
const html = await readFile(`${__dirname}/${filepath}.html`, "utf-8");
40+
let body;
41+
if (filepath.endsWith(".json")) {
42+
body = await readFile(`${__dirname}/${filepath}`, "utf-8");
43+
} else {
44+
body = await readFile(`${__dirname}/${filepath}.html`, "utf-8");
45+
}
4146
return {
42-
body: html,
47+
body,
4348
statusCode: 200,
4449
};
4550
} catch (e) {

0 commit comments

Comments
 (0)