Skip to content

Commit 4710797

Browse files
committed
new input format
1 parent 1b27fa2 commit 4710797

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

exampleConfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"port": 3000,
2323
"path": "/test",
2424
"input": {
25-
"method": "text2"
25+
"request": "text2"
2626
},
2727
"output": {
2828
"headers": {
@@ -39,7 +39,7 @@
3939
"port": 3000,
4040
"path": "/test1",
4141
"input": {
42-
"payload": {
42+
"request": {
4343
"name": "John Doe",
4444
"age": 30
4545
}

src/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ class CreateServer {
3131
}
3232
config.output.response = fs.readFileSync(config.output.filePath, "utf-8");
3333
}
34+
if (config.input.filePath) {
35+
if (!fs.existsSync(config.input.filePath)) {
36+
throw new Error(`File not found at path: ${config.input.filePath}`);
37+
}
38+
config.input.request = fs.readFileSync(config.input.filePath, "utf-8");
39+
}
3440
validateData(config);
3541
return config;
3642
} catch (err) {
@@ -80,7 +86,7 @@ class CreateServer {
8086
if (config.method.includes(req.method) && config.path === reqUrl) {
8187
console.log(chalk.green("Matched Config:"), config.name);
8288

83-
if (deepCompare(reqObj, config.input)) {
89+
if (deepCompare(reqObj, config.input.request)) {
8490
console.log(chalk.green("Input Matched"));
8591
httpResponse(res, config);
8692
return;

0 commit comments

Comments
 (0)