Update adapter script.

This commit is contained in:
Dillon Kearns 2023-01-22 15:36:11 -08:00
parent 7f35edd60e
commit e835b494c9
2 changed files with 8 additions and 14 deletions

View File

@ -19,18 +19,18 @@ export default async function run({
renderFunctionFilePath,
"./functions/server-render/elm-pages-cli.js"
);
fs.copyFileSync(portsFilePath, "./functions/render/custom-backend-task.js");
fs.copyFileSync(portsFilePath, "./functions/render/custom-backend-task.mjs");
fs.copyFileSync(
portsFilePath,
"./functions/server-render/custom-backend-task.js"
"./functions/server-render/custom-backend-task.mjs"
);
fs.writeFileSync(
"./functions/render/index.js",
"./functions/render/index.mjs",
rendererCode(true, htmlTemplate)
);
fs.writeFileSync(
"./functions/server-render/index.js",
"./functions/server-render/index.mjs",
rendererCode(false, htmlTemplate)
);
// TODO rename functions/render to functions/fallback-render
@ -128,12 +128,7 @@ export const handler = render;`
async function render(event, context) {
const requestTime = new Date();
console.log(JSON.stringify(event));
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compiledElmPath = path.join(__dirname, "elm-pages-cli.js");
const compiledPortsFile = path.join(__dirname, "custom-backend-task.js");
const compiledPortsFile = "./custom-backend-task.mjs";
try {
const basePath = "/";
@ -143,7 +138,7 @@ async function render(event, context) {
const renderResult = await renderer.render(
compiledPortsFile,
basePath,
(await import(path.resolve(compiledElmPath))).default,
(await import("./elm-pages-cli.js")).default,
mode,
event.path,
await reqToJson(event, requestTime),

View File

@ -2,8 +2,6 @@ import * as seo from "./seo-renderer.js";
import * as packageJson from "../../package.json" assert { type: "json" };
import * as path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const cliVersion = packageJson.version;
@ -27,6 +25,8 @@ export function wrapHtml(basePath, fromElm, contentDatPayload) {
* @param {(context: {cliVersion: string;}) => string} userHeadTagsTemplate
*/
export function templateHtml(devMode, userHeadTagsTemplate) {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
return /* html */ `<!DOCTYPE html>
<!-- ROOT --><html lang="en">
<head>
@ -81,4 +81,3 @@ export function replaceTemplate(processedTemplate, info) {
.replace(/<!--\s*PLACEHOLDER_HTML\s* -->/, info.html)
.replace(/<!-- ROOT -->\S*<html lang="en">/m, info.rootElement);
}