jgloo 1.7.0 → 1.8.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/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ <a name="1.8.0"></a>
2
+
3
+ ## [1.8.0](https://github.com/zosma180/jgloo/compare/1.7.0...1.8.0) (2022-07-29)
4
+
5
+ ### Features
6
+
7
+ - Added the optional "priority" property to the configuration
8
+
9
+ ---
10
+
1
11
  <a name="1.7.0"></a>
2
12
 
3
13
  ## [1.7.0](https://github.com/zosma180/jgloo/compare/1.6.1...1.7.0) (2022-07-28)
package/README.md CHANGED
@@ -46,6 +46,7 @@ Now you are ready to [create your first API](#create-a-simple-api).
46
46
  - [Expose the static files](#expose-the-static-files)
47
47
  - [Handle requests with file uploads](#handle-requests-with-file-uploads)
48
48
  - [Simulate network delay](#simulate-network-delay)
49
+ - [Manage path conflicts](#manage-path-conflicts)
49
50
  - [Run the server](#run-the-server)
50
51
 
51
52
  ---
@@ -197,6 +198,25 @@ module.exports = {
197
198
 
198
199
  ---
199
200
 
201
+ ### Manage path conflicts
202
+
203
+ If you have a scenario where two or more paths have conflicting values, e.g.:
204
+ - /my-path/:id
205
+ - /my-path/my-sub-path
206
+
207
+ you can add the `priority` property to your API configuration:
208
+
209
+ ```javascript
210
+ module.exports = {
211
+ ...
212
+ priority: 2
213
+ };
214
+ ```
215
+
216
+ The default value is 0. The api with the higher value will be used.
217
+
218
+ ---
219
+
200
220
  ### Run the server
201
221
 
202
222
  To run the server execute the following command in your project root:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jgloo",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "The coldest mock server.",
5
5
  "homepage": "https://github.com/zosma180/jgloo",
6
6
  "repository": {
package/server.js CHANGED
@@ -64,16 +64,17 @@ if (!existsSync(apiPath)) {
64
64
  process.exit(2);
65
65
  }
66
66
 
67
- const api = walk(apiPath).filter(file => file.endsWith('.js') );
67
+ const api = walk(apiPath)
68
+ .filter(file => file.endsWith('.js'))
69
+ .map(file => require(file))
70
+ .sort((a, b) => (b.priority || 0) - (a.priority || 0));
68
71
 
69
72
  if (!api.length) {
70
73
  console.error(`No API file defined. Create one.`);
71
74
  process.exit(2);
72
75
  }
73
76
 
74
- api.forEach((file) => {
75
- const config = require(file);
76
-
77
+ api.forEach(config => {
77
78
  // Add the API delay, if it is provided
78
79
  if (config.delay) {
79
80
  app.use(config.path, getDelayMiddleware(config.delay));
@@ -90,3 +91,4 @@ api.forEach((file) => {
90
91
 
91
92
  const message = `jgloo builded on the ice shelf "${root}" and the port ${port}.`;
92
93
  app.listen(port, () => console.log('\x1b[36m', message));
94
+