Use __dirname to resolve path.

This commit is contained in:
Dillon Kearns 2021-03-23 22:28:00 -07:00
parent cf78609367
commit d63ce72018
2 changed files with 12 additions and 7 deletions

View File

@ -1,13 +1,16 @@
// const path = require("path");
const path = require("path");
exports.handler = async function (event, context) {
console.log(JSON.stringify(event));
// process.chdir(path.join(__dirname, "../../"));
// process.chdir("../");
// const compiledElmPath = path.join(process.cwd(), "elm-pages-cli.js");
const compiledElmPath = path.join(__dirname, "elm-pages-cli.js");
const renderer = require("../../../../generator/src/render");
console.log("pwd", process.cwd());
return {
body: (await renderer()).htmlString,
body: (await renderer(compiledElmPath)).htmlString,
statusCode: 200,
};
};

View File

@ -15,14 +15,17 @@ process.on("unhandledRejection", (error) => {
process.exit(1);
});
module.exports = async function run() {
module.exports = async function run(/** @type {string} */ compiledElmPath) {
XMLHttpRequest = require("xhr2");
console.log("RENDER NEW");
const result = await runElmApp();
const result = await runElmApp(compiledElmPath);
return result;
};
function runElmApp() {
/**
* @param {string} compiledElmPath
*/
function runElmApp(compiledElmPath) {
process.on("beforeExit", (code) => {
if (foundErrors) {
process.exit(1);
@ -32,10 +35,9 @@ function runElmApp() {
});
return new Promise((resolve, _) => {
const ELM_FILE_PATH = path.join(process.cwd(), "elm-pages-cli.js");
const mode /** @type { "dev" | "prod" } */ = "elm-to-html-beta";
const staticHttpCache = {};
const app = require(ELM_FILE_PATH).Elm.Main.init({
const app = require(compiledElmPath).Elm.Main.init({
flags: { secrets: process.env, mode, staticHttpCache },
});