@safagayret/bemirror 1.0.0
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/LICENSE +21 -0
- package/README.md +85 -0
- package/bin/bemirror +20 -0
- package/endpoints.json +122 -0
- package/index.js +8 -0
- package/package.json +47 -0
- package/public/css/style.css +954 -0
- package/public/index.html +505 -0
- package/public/js/app.js +1008 -0
- package/server.js +322 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Safa Gayret
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# be.mirror
|
|
2
|
+
|
|
3
|
+
> **Fake mirror your backend, fast.**
|
|
4
|
+
|
|
5
|
+
**be.mirror** is an ultra-lightweight, zero-backend, local Node.js API mock server built for frontend teams. It allows you to visualize, create, and interact with complex mock endpoints completely locally without the heavy setup of databases or third-party cloud tools.
|
|
6
|
+
|
|
7
|
+
## ✨ Features
|
|
8
|
+
|
|
9
|
+
- **Zero Backend Database:** Everything runs in `localStorage` or in a flat `JSON` file.
|
|
10
|
+
- **Instant Prod URL Mapping:** Effortlessly configure endpoints to a production format.
|
|
11
|
+
- **Live Network Delay Testing:** Set specific request delays (e.g. 500ms) to test your frontend loaders safely.
|
|
12
|
+
- **Strict Parameter & Body Validation:** Expect precise queries or payloads; returns HTTP 400 automatically if not met.
|
|
13
|
+
- **Export / Import Seamlessly:** Share your endpoint configurations with other developers via JSON without hassle. Merge or overwrite local instances.
|
|
14
|
+
- **Code Generator:** Instantly copy valid cURL or JS `fetch()` requests directly from the UI.
|
|
15
|
+
- **Responsive UI:** Works nicely on mobile devices and tablets using an intuitive postman-style flow.
|
|
16
|
+
|
|
17
|
+
## 🚀 Getting Started
|
|
18
|
+
|
|
19
|
+
### Prerequisites
|
|
20
|
+
|
|
21
|
+
Make sure you have Node.js installed (v18+ recommended).
|
|
22
|
+
|
|
23
|
+
### Installation
|
|
24
|
+
|
|
25
|
+
Install `bemirror` as a development dependency:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install --save-dev bemirror
|
|
29
|
+
# or
|
|
30
|
+
pnpm add -D bemirror
|
|
31
|
+
# or
|
|
32
|
+
yarn add -D bemirror
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Run the server
|
|
36
|
+
|
|
37
|
+
Start the mock server directly with `npx`:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx bemirror
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Or add it to your project scripts:
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"scripts": {
|
|
48
|
+
"bemirror": "bemirror"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Then run:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm run bemirror
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
You can also set a custom port:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npx bemirror --port=9000
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Once started, open `http://localhost:8000` (or your configured port) to use the UI.
|
|
66
|
+
|
|
67
|
+
## 🛠 Usage
|
|
68
|
+
|
|
69
|
+
- Focus on the **Sidebar**: Create a **Project** first, then an **Entity**, and add your mapped **Endpoints**.
|
|
70
|
+
- **Edit your Endpoint:** In the main view, define routing paths, params, and payload rules.
|
|
71
|
+
- **Mock URL Test:** Consume APIs by pointing your React/Vue/Svelte frontend directly to the provided **Mock URL**.
|
|
72
|
+
- **Proxy Test:** Use the built in proxy to make real network requests to external URLs avoiding standard CORS errors in the browser.
|
|
73
|
+
|
|
74
|
+
## 🤝 Contributing
|
|
75
|
+
|
|
76
|
+
Contributions are totally welcome! This is an open-source tool aiming at significantly reducing friction during frontend development phases.
|
|
77
|
+
|
|
78
|
+
1. Fork the repo and create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
79
|
+
2. Commit your changes (`git commit -m 'Added amazing feature'`)
|
|
80
|
+
3. Push to the branch (`git push origin feature/amazing-feature`)
|
|
81
|
+
4. Open a pull request.
|
|
82
|
+
|
|
83
|
+
## 📄 License
|
|
84
|
+
|
|
85
|
+
This project is licensed under the MIT License.
|
package/bin/bemirror
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { startBemirrorServer } = require('../index')
|
|
3
|
+
|
|
4
|
+
const args = process.argv.slice(2)
|
|
5
|
+
const options = {}
|
|
6
|
+
|
|
7
|
+
for (const arg of args) {
|
|
8
|
+
if (arg.startsWith('--port=')) {
|
|
9
|
+
options.port = parseInt(arg.split('=')[1], 10)
|
|
10
|
+
} else if (arg === '--help' || arg === '-h') {
|
|
11
|
+
console.log('Usage: bemirror [--port=<port>]')
|
|
12
|
+
process.exit(0)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const { server } = startBemirrorServer(options)
|
|
17
|
+
server.on('error', (err) => {
|
|
18
|
+
console.error('bemirror failed to start:', err.message)
|
|
19
|
+
process.exit(1)
|
|
20
|
+
})
|
package/endpoints.json
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
{
|
|
2
|
+
"projects": [
|
|
3
|
+
{
|
|
4
|
+
"id": "p-product-api",
|
|
5
|
+
"name": "Product API",
|
|
6
|
+
"entities": [
|
|
7
|
+
{
|
|
8
|
+
"id": "e-products",
|
|
9
|
+
"name": "Products",
|
|
10
|
+
"endpoints": [
|
|
11
|
+
{
|
|
12
|
+
"id": "ep-get-products",
|
|
13
|
+
"method": "GET",
|
|
14
|
+
"path": "/products",
|
|
15
|
+
"statusCode": 200,
|
|
16
|
+
"delay": 200,
|
|
17
|
+
"expectedParams": "",
|
|
18
|
+
"expectedPayload": "",
|
|
19
|
+
"authorization": {
|
|
20
|
+
"type": "Basic Auth",
|
|
21
|
+
"value": "{{username}}:{{password}}"
|
|
22
|
+
},
|
|
23
|
+
"headers": [
|
|
24
|
+
{
|
|
25
|
+
"key": "Content-Type",
|
|
26
|
+
"value": "application/json"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"key": "X-API-Key",
|
|
30
|
+
"value": "{{apiKey}}"
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
"responseBody": "{\n \"products\": [\n {\n \"id\": 1,\n \"name\": \"Laptop\",\n \"price\": 999.99,\n \"category\": \"Electronics\"\n },\n {\n \"id\": 2,\n \"name\": \"Book\",\n \"price\": 19.99,\n \"category\": \"Education\"\n }\n ]\n}"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"id": "ep-post-product",
|
|
37
|
+
"method": "POST",
|
|
38
|
+
"path": "/products",
|
|
39
|
+
"statusCode": 201,
|
|
40
|
+
"delay": 300,
|
|
41
|
+
"expectedParams": "",
|
|
42
|
+
"expectedPayload": "{\n \"name\": \"string\",\n \"price\": \"number\",\n \"category\": \"string\"\n}",
|
|
43
|
+
"authorization": {
|
|
44
|
+
"type": "Bearer Token",
|
|
45
|
+
"value": "{{token}}"
|
|
46
|
+
},
|
|
47
|
+
"headers": [
|
|
48
|
+
{
|
|
49
|
+
"key": "Content-Type",
|
|
50
|
+
"value": "application/json"
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
"responseBody": "{\n \"id\": 3,\n \"name\": \"New Product\",\n \"price\": 49.99,\n \"category\": \"Test\",\n \"createdAt\": \"2024-01-01T00:00:00Z\"\n}"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"id": "ep-put-product",
|
|
57
|
+
"method": "PUT",
|
|
58
|
+
"path": "/products/:id",
|
|
59
|
+
"statusCode": 200,
|
|
60
|
+
"delay": 250,
|
|
61
|
+
"expectedParams": "",
|
|
62
|
+
"expectedPayload": "{\n \"name\": \"string\",\n \"price\": \"number\",\n \"category\": \"string\"\n}",
|
|
63
|
+
"authorization": {
|
|
64
|
+
"type": "Bearer Token",
|
|
65
|
+
"value": "{{token}}"
|
|
66
|
+
},
|
|
67
|
+
"headers": [
|
|
68
|
+
{
|
|
69
|
+
"key": "Content-Type",
|
|
70
|
+
"value": "application/json"
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
"responseBody": "{\n \"id\": 1,\n \"name\": \"Updated Laptop\",\n \"price\": 1099.99,\n \"category\": \"Electronics\",\n \"updatedAt\": \"2024-01-01T00:00:00Z\"\n}"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"id": "ep-delete-product",
|
|
77
|
+
"method": "DELETE",
|
|
78
|
+
"path": "/products/:id",
|
|
79
|
+
"statusCode": 204,
|
|
80
|
+
"delay": 150,
|
|
81
|
+
"expectedParams": "",
|
|
82
|
+
"expectedPayload": "",
|
|
83
|
+
"authorization": {
|
|
84
|
+
"type": "Bearer Token",
|
|
85
|
+
"value": "{{token}}"
|
|
86
|
+
},
|
|
87
|
+
"headers": [],
|
|
88
|
+
"responseBody": ""
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"id": "p-jiqoz2ox2",
|
|
96
|
+
"name": "lorem",
|
|
97
|
+
"entities": [
|
|
98
|
+
{
|
|
99
|
+
"id": "4r96tesww",
|
|
100
|
+
"name": "ipsum",
|
|
101
|
+
"endpoints": [
|
|
102
|
+
{
|
|
103
|
+
"id": "j4e6t3wui",
|
|
104
|
+
"method": "GET",
|
|
105
|
+
"path": "/dolor",
|
|
106
|
+
"statusCode": 200,
|
|
107
|
+
"delay": 0,
|
|
108
|
+
"expectedParams": "",
|
|
109
|
+
"expectedPayload": "",
|
|
110
|
+
"responseBody": "{\"success\": true}",
|
|
111
|
+
"authorization": {
|
|
112
|
+
"type": "None",
|
|
113
|
+
"value": ""
|
|
114
|
+
},
|
|
115
|
+
"headers": []
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
}
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@safagayret/bemirror",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Fake mirror your backend, fast",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"bemirror": "./bin/bemirror"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "node server.js",
|
|
11
|
+
"dev": "node server.js",
|
|
12
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"mock",
|
|
16
|
+
"server",
|
|
17
|
+
"api",
|
|
18
|
+
"testing",
|
|
19
|
+
"development"
|
|
20
|
+
],
|
|
21
|
+
"author": "Safa Gayret",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18.0.0"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"index.js",
|
|
28
|
+
"server.js",
|
|
29
|
+
"bin/",
|
|
30
|
+
"public/",
|
|
31
|
+
"mocks/",
|
|
32
|
+
"endpoints.json",
|
|
33
|
+
"variables.json"
|
|
34
|
+
],
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/gayret/bemirror.git"
|
|
38
|
+
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/gayret/bemirror/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/gayret/bemirror#readme",
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"cors": "^2.8.6",
|
|
45
|
+
"express": "^5.2.1"
|
|
46
|
+
}
|
|
47
|
+
}
|