summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-03-06 11:57:09 -0300
committerEuAndreh <eu@euandre.org>2024-03-06 11:57:09 -0300
commit331738a0f69e00d12d44f27a717b3b73733b485a (patch)
treee8bc0208326f8ad469bd8cb3ef4fcd395a326d37 /src
parenttests/runner.mjs: Add missing await in t.test("", () => {}) (diff)
downloadpapod-331738a0f69e00d12d44f27a717b3b73733b485a.tar.gz
papod-331738a0f69e00d12d44f27a717b3b73733b485a.tar.xz
src/hero.mjs: Add rmIf() and mkfifo()
Diffstat (limited to 'src')
-rw-r--r--src/hero.mjs24
-rw-r--r--src/web.mjs6
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 });
};