feat: support async handlers
This commit is contained in:
parent
9d625b0fd5
commit
66911677f0
1 changed files with 6 additions and 5 deletions
11
index.js
11
index.js
|
|
@ -730,7 +730,7 @@ function embedHTML(url) {
|
||||||
return `<div hx-get="${url}" hx-trigger="load"></div>`;
|
return `<div hx-get="${url}" hx-trigger="load"></div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
app.all("*", (req, res) => {
|
app.all("*", async (req, res) => {
|
||||||
const req_path = req.path;
|
const req_path = req.path;
|
||||||
const verb = req.method;
|
const verb = req.method;
|
||||||
|
|
||||||
|
|
@ -779,10 +779,11 @@ app.all("*", (req, res) => {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
return vm.runInContext(
|
const handlerScript = new vm.Script(route.handler, { filename: `handler_${route.id}.js` });
|
||||||
(route.handler += `\n\nhandler(req, res)`),
|
// Prepare the execution code that invokes `handler(req, res)` and awaits it
|
||||||
context,
|
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) {
|
} catch (e) {
|
||||||
const error = e.stack ? `${e}\n\n${e.stack}` : `${e}`;
|
const error = e.stack ? `${e}\n\n${e.stack}` : `${e}`;
|
||||||
model.createLog(db, structure.id, route.id, error, true);
|
model.createLog(db, structure.id, route.id, error, true);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue