elm-pages-v3-beta/examples/pokedex/adapter.js

40 lines
1.2 KiB
JavaScript
Raw Normal View History

const fs = require("fs");
async function run({ renderFunctionFilePath, routePatterns }) {
fs.copyFileSync(
renderFunctionFilePath,
"./functions/render/elm-pages-cli.js"
);
// TODO also copy renderFunctionFilePath to server-render function folder?
// TODO copy DPR render serverless function to functions folder
// TODO copy server-request render serverless function to functions folder
// TODO rename functions/render to functions/fallback-render
// TODO prepend instead of writing file
console.log(routePatterns);
const redirectsFile =
routePatterns
.filter(isServerSide)
.map((route) => {
2021-12-16 02:44:48 +03:00
if (route.kind === "prerender-with-fallback") {
2021-12-16 02:48:16 +03:00
return `${route.pathPattern} /.netlify/functions/render 200`;
} else {
2021-12-16 02:48:16 +03:00
return `${route.pathPattern} /.netlify/functions/server-render 200`;
}
})
.join("\n") + "\n";
fs.writeFileSync("dist/_redirects", redirectsFile);
}
function isServerSide(route) {
return (
route.kind === "prerender-with-fallback" || route.kind === "serverless"
);
}
run({
renderFunctionFilePath: "./elm-stuff/elm-pages/elm.js",
routePatterns: JSON.parse(fs.readFileSync("dist/route-patterns.json")),
});