cpeak 2.1.0 → 2.2.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/README.md +18 -2
- package/lib/index.js +7 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ This is an educational project that was started as part of the [Understanding No
|
|
|
30
30
|
- [serveStatic](#servestatic)
|
|
31
31
|
- [parseJSON](#parsejson)
|
|
32
32
|
- [Complete Example](#complete-example)
|
|
33
|
+
- [Versioning Notice](#versioning-notice)
|
|
33
34
|
|
|
34
35
|
## Getting Started
|
|
35
36
|
|
|
@@ -132,7 +133,7 @@ Here’s how we can read both:
|
|
|
132
133
|
// Imagine request URL is example.com/test/my-title/more-text?filter=newest
|
|
133
134
|
server.route("patch", "/test/:title/more-text", (req, res) => {
|
|
134
135
|
const title = req.vars.title;
|
|
135
|
-
const filter = req.params.
|
|
136
|
+
const filter = req.params.filter;
|
|
136
137
|
|
|
137
138
|
console.log(title); // my-title
|
|
138
139
|
console.log(filter); // newest
|
|
@@ -294,7 +295,7 @@ server.route("get", "/api/document/:title", (req, res, handleErr) => {
|
|
|
294
295
|
const title = req.vars.title;
|
|
295
296
|
|
|
296
297
|
// Reading URL parameters (like /users?filter=active)
|
|
297
|
-
const filter = req.params.
|
|
298
|
+
const filter = req.params.filter;
|
|
298
299
|
|
|
299
300
|
// Reading JSON request body
|
|
300
301
|
const anything = req.body.anything;
|
|
@@ -329,3 +330,18 @@ server.listen(3000, () => {
|
|
|
329
330
|
console.log("Server has started on port 3000");
|
|
330
331
|
});
|
|
331
332
|
```
|
|
333
|
+
|
|
334
|
+
## Versioning Notice
|
|
335
|
+
|
|
336
|
+
#### Version `1.x.x`
|
|
337
|
+
|
|
338
|
+
Version `1.x.x` represents the initial release of our framework, developed during the _Understanding Node.js Core Concepts_ course. These versions laid the foundation for our project.
|
|
339
|
+
|
|
340
|
+
#### Version `2.x.x`
|
|
341
|
+
|
|
342
|
+
All version `2.x.x` releases are considered to be in active development, following the completion of the course. These versions include ongoing feature additions and API changes as we refine the framework. Frequent updates may require code changes, so version `2.x.x` is not recommended for production environments.
|
|
343
|
+
For new features, bug fixes, and other changes that don't break existing code, the patch version will be increased. For changes that break existing code, the minor version will be increased.
|
|
344
|
+
|
|
345
|
+
#### Version `3.x.x`
|
|
346
|
+
|
|
347
|
+
Version `3.x.x` and beyond will be our first production-ready releases. These versions are intended for stable, long-term use, with a focus on backward compatibility and minimal breaking changes.
|
package/lib/index.js
CHANGED
|
@@ -34,9 +34,8 @@ class Cpeak {
|
|
|
34
34
|
res.end(JSON.stringify(data));
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
//
|
|
37
|
+
// Get the url without the URL parameters
|
|
38
38
|
const urlWithoutParams = req.url.split("?")[0];
|
|
39
|
-
req.params = new URLSearchParams(req.url.split("?")[1]);
|
|
40
39
|
|
|
41
40
|
// Run all the middleware functions before we run the corresponding route
|
|
42
41
|
const runMiddleware = (req, res, middleware, index) => {
|
|
@@ -46,10 +45,15 @@ class Cpeak {
|
|
|
46
45
|
const match = urlWithoutParams.match(route.regex);
|
|
47
46
|
|
|
48
47
|
if (match) {
|
|
48
|
+
// Parse the URL parameters (like /users?key1=value1&key2=value2)
|
|
49
|
+
const params = new URLSearchParams(req.url.split("?")[1]);
|
|
50
|
+
req.params = Object.fromEntries(params.entries());
|
|
51
|
+
|
|
49
52
|
// Parse the URL variables from the matched route (like /users/:id)
|
|
50
53
|
const vars = this.#extractVars(route.path, match);
|
|
51
|
-
// Call the route handler with request and URL variables
|
|
52
54
|
req.vars = vars;
|
|
55
|
+
|
|
56
|
+
// Call the route handler with the modified req and res objects
|
|
53
57
|
return route.cb(req, res, (error) => {
|
|
54
58
|
res.setHeader("Connection", "close");
|
|
55
59
|
this.handleErr(error, req, res);
|