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>`;
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue