Skip to content

Commit

Permalink
chore: log error when require does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
svedova committed Apr 18, 2023
1 parent 5e966a2 commit b9ad7c4
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/utils/callbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,11 @@ export const handleApi = (
const file = matchPath(cachedFiles, requestPath, req.method);

if (file) {
const importPath = path.join(file.path, file.name);

try {
const mod = require(importPath);
const mod = require(path.join(file.path, file.name));
return mod.default ? mod.default(req, res) : mod(req, res);
} catch {
return import(importPath).then((mod) => {
return mod.default ? mod.default(req, res) : mod(req, res);
});
} catch (e) {
console.error(e);
}
}

Expand Down

0 comments on commit b9ad7c4

Please sign in to comment.