diff --git a/index.js b/index.js index 5058516..f71230e 100644 --- a/index.js +++ b/index.js @@ -730,7 +730,7 @@ function embedHTML(url) { return `
`; } -app.all("*", (req, res) => { +app.all("*", async (req, res) => { const req_path = req.path; const verb = req.method; @@ -779,10 +779,11 @@ app.all("*", (req, res) => { ), ); }; - return vm.runInContext( - (route.handler += `\n\nhandler(req, res)`), - context, - ); + const handlerScript = new vm.Script(route.handler, { filename: `handler_${route.id}.js` }); + // Prepare the execution code that invokes `handler(req, res)` and awaits it + const executionScript = new vm.Script(`handler(req, res); `, { filename: `execution_${route.id}.js` }); + await handlerScript.runInContext(context); + const result = await executionScript.runInContext(context); } catch (e) { const error = e.stack ? `${e}\n\n${e.stack}` : `${e}`; model.createLog(db, structure.id, route.id, error, true);