360-mock-server 1.2.0 β 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/bin/cli.js +4 -4
- package/lib/server.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ Thatβs it! π
|
|
|
41
41
|
The mock server will start at:
|
|
42
42
|
|
|
43
43
|
```
|
|
44
|
-
http://localhost:
|
|
44
|
+
http://localhost:6000
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
|
|
@@ -83,7 +83,7 @@ Once the server starts, you can interact with it directly from the terminal:
|
|
|
83
83
|
**Base URL**
|
|
84
84
|
|
|
85
85
|
```
|
|
86
|
-
http://localhost:
|
|
86
|
+
http://localhost:6000
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
### Example Endpoints
|
|
@@ -158,7 +158,7 @@ GET /faker/fields
|
|
|
158
158
|
<summary><strong>Fetch API</strong></summary>
|
|
159
159
|
|
|
160
160
|
```javascript
|
|
161
|
-
const API = 'http://localhost:
|
|
161
|
+
const API = 'http://localhost:6000';
|
|
162
162
|
|
|
163
163
|
// CREATE
|
|
164
164
|
await fetch(`${API}/users`, {
|
|
@@ -189,7 +189,7 @@ await fetch(`${API}/users/123`, { method: 'DELETE' });
|
|
|
189
189
|
```javascript
|
|
190
190
|
import axios from 'axios';
|
|
191
191
|
|
|
192
|
-
const API = 'http://localhost:
|
|
192
|
+
const API = 'http://localhost:6000';
|
|
193
193
|
|
|
194
194
|
// CREATE
|
|
195
195
|
await axios.post(`${API}/users`, {
|
|
@@ -216,7 +216,7 @@ await axios.delete(`${API}/users/123`);
|
|
|
216
216
|
|
|
217
217
|
| Option | Description | Default |
|
|
218
218
|
| -------- | -------------- | ---------------- |
|
|
219
|
-
| `--port` | Server port | `
|
|
219
|
+
| `--port` | Server port | `6000` |
|
|
220
220
|
| `--file` | Data file name | `mock-data.json` |
|
|
221
221
|
|
|
222
222
|
### Examples
|
package/bin/cli.js
CHANGED
|
@@ -9,7 +9,7 @@ const readline = require("readline");
|
|
|
9
9
|
const packageJson = require("../package.json");
|
|
10
10
|
|
|
11
11
|
// Helper function for making HTTP requests
|
|
12
|
-
function makeRequest(method, endpoint, data, port = "
|
|
12
|
+
function makeRequest(method, endpoint, data, port = "6000") {
|
|
13
13
|
return new Promise((resolve) => {
|
|
14
14
|
const upperMethod = method.toUpperCase();
|
|
15
15
|
const urlPath = endpoint.startsWith("/") ? endpoint : "/" + endpoint;
|
|
@@ -166,7 +166,7 @@ program
|
|
|
166
166
|
program
|
|
167
167
|
.command("run", { isDefault: true })
|
|
168
168
|
.description("Start server + interactive mode (recommended)")
|
|
169
|
-
.option("-p, --port <port>", "Port number", "
|
|
169
|
+
.option("-p, --port <port>", "Port number", "6000")
|
|
170
170
|
.option("-f, --file <filename>", "Data file name", "mock-data.json")
|
|
171
171
|
.action((options) => {
|
|
172
172
|
const dataFile = path.join(process.cwd(), options.file);
|
|
@@ -192,7 +192,7 @@ program
|
|
|
192
192
|
program
|
|
193
193
|
.command("start")
|
|
194
194
|
.description("Start the mock server only (no interactive mode)")
|
|
195
|
-
.option("-p, --port <port>", "Port number", "
|
|
195
|
+
.option("-p, --port <port>", "Port number", "6000")
|
|
196
196
|
.option("-f, --file <filename>", "Data file name", "mock-data.json")
|
|
197
197
|
.action((options) => {
|
|
198
198
|
const dataFile = path.join(process.cwd(), options.file);
|
|
@@ -266,7 +266,7 @@ program
|
|
|
266
266
|
program
|
|
267
267
|
.command("req <method> <endpoint> [data]")
|
|
268
268
|
.description("Make single API request")
|
|
269
|
-
.option("-p, --port <port>", "Server port", "
|
|
269
|
+
.option("-p, --port <port>", "Server port", "6000")
|
|
270
270
|
.action(async (method, endpoint, data, options) => {
|
|
271
271
|
await makeRequest(method, endpoint, data, options.port);
|
|
272
272
|
});
|
package/lib/server.js
CHANGED
|
@@ -5,7 +5,7 @@ const cors = require("cors");
|
|
|
5
5
|
const { faker } = require("@faker-js/faker");
|
|
6
6
|
|
|
7
7
|
const app = express();
|
|
8
|
-
const PORT = process.env.PORT ||
|
|
8
|
+
const PORT = process.env.PORT || 6000;
|
|
9
9
|
const DATA_FILE = process.env.DATA_FILE || path.join(process.cwd(), "mock-data.json");
|
|
10
10
|
|
|
11
11
|
app.use(cors());
|