diff options
Diffstat (limited to 'src/hero.mjs')
-rw-r--r-- | src/hero.mjs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/hero.mjs b/src/hero.mjs index 53f3086..6b6fa77 100644 --- a/src/hero.mjs +++ b/src/hero.mjs @@ -1,7 +1,10 @@ -import assert from "node:assert/strict"; -import crypto from "node:crypto"; -import http from "node:http"; -import process from "node:process"; +import assert from "node:assert/strict"; +import child_process from "node:child_process"; +import crypto from "node:crypto"; +import fs from "node:fs"; +import http from "node:http"; +import process from "node:process"; +import util from "node:util"; import * as u from "./utils.mjs"; @@ -79,13 +82,13 @@ export const firstParamMatch = (tree, segments, params) => { const subtree = tree[seg]; if (subtree) { const submatch = firstParamMatch(subtree, nextSegments, params); - // propagation of the end of recursion + /// propagation of the end of recursion if (submatch) { return submatch; } } - // literal matching failed, we now look for patterns that might match + /// literal matching failed, we now look for patterns that might match const paramOptions = Object.keys(tree) .filter(s => s.startsWith(":")) .sort(u.strSortFn); @@ -326,6 +329,15 @@ export const lineHandlerFn = ({ export const lineHandler = lineHandlerFn(); +export const rmIf = path => { + if (fs.existsSync(path)) { + fs.unlinkSync(path); + } +}; + +export const mkfifo = path => + child_process.execFileSync("mkfifo", [path]); + export const buildRoutes = (routes, globalInterceptors = []) => routes.reduce( (acc, [methods, path, handlerFn, interceptors = []]) => |