diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hero.mjs | 24 | ||||
-rw-r--r-- | src/web.mjs | 6 |
2 files changed, 21 insertions, 9 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 = []]) => diff --git a/src/web.mjs b/src/web.mjs index 3ca2544..23ae5ff 100644 --- a/src/web.mjs +++ b/src/web.mjs @@ -12,7 +12,7 @@ const server = hero.buildServer("papo", [ [ "GET", "/api/socket", getSocket ], ]); -export const app = async path => { - await server.listen(path); - hero.log.info({ type: "starting-server", path }); +export const app = async (...args) => { + await server.listen(...args); + hero.log.info({ type: "starting-server", args }); }; |