Skip to content

Commit 198e0d6

Browse files
committed
refactor(start): assert payload file extension and allow to omit it
1 parent 03d24d7 commit 198e0d6

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/commands/http.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@ import path from "node:path";
44
// Import Internal Dependencies
55
import { buildServer } from "../http-server/index.js";
66

7-
export async function start(json = "nsecure-result.json", options = {}) {
7+
export async function start(
8+
payloadFileBasename = "nsecure-result.json",
9+
options = {}
10+
) {
811
const port = Number(options.port);
9-
const dataFilePath = path.join(process.cwd(), json);
12+
const fileExtension = path.extname(payloadFileBasename);
13+
if (fileExtension !== ".json" && fileExtension !== "") {
14+
throw new Error("You must provide a JSON file (scanner payload) to open");
15+
}
16+
17+
const dataFilePath = path.join(
18+
process.cwd(),
19+
fileExtension === "" ? `${payloadFileBasename}.json` : payloadFileBasename
20+
);
1021

1122
const httpServer = buildServer(dataFilePath, {
1223
port: Number.isNaN(port) ? 0 : port

0 commit comments

Comments
 (0)