spooder 4.5.5 → 4.5.6
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 +11 -0
- package/package.json +1 -1
- package/src/api.ts +16 -0
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ The `CLI` component of `spooder` is a global command-line tool for running serve
|
|
|
38
38
|
- [`serve(port: number): Server`](#api-serving-serve)
|
|
39
39
|
- [API > Routing](#api-routing)
|
|
40
40
|
- [`server.route(path: string, handler: RequestHandler, method: HTTP_METHODS)`](#api-routing-server-route)
|
|
41
|
+
- [`server.unroute(path: string)`](#api-routing-server-unroute)
|
|
41
42
|
- [HTTP Methods](#api-routing-methods)
|
|
42
43
|
- [Redirection Routes](#api-routing-redirection-routes)
|
|
43
44
|
- [Status Code Text](#api-routing-status-code-text)
|
|
@@ -501,6 +502,16 @@ server.route('/test/route', (req, url) => {
|
|
|
501
502
|
});
|
|
502
503
|
```
|
|
503
504
|
|
|
505
|
+
<a id="api-routing-server-unrouote"></a>
|
|
506
|
+
### 🔧 `server.unroute(path: string)`
|
|
507
|
+
|
|
508
|
+
Unregister a specific route.
|
|
509
|
+
|
|
510
|
+
```ts
|
|
511
|
+
server.route('/test/route', () => {});
|
|
512
|
+
server.unroute('/test/route');
|
|
513
|
+
```
|
|
514
|
+
|
|
504
515
|
<a id="api-routing-methods"></a>
|
|
505
516
|
### HTTP Methods
|
|
506
517
|
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -804,6 +804,22 @@ export function serve(port: number) {
|
|
|
804
804
|
routes.push([path.split('/'), handler, method]);
|
|
805
805
|
},
|
|
806
806
|
|
|
807
|
+
/** Unregister a specific route */
|
|
808
|
+
unroute: (path: string): void => {
|
|
809
|
+
const path_parts = path.split('/');
|
|
810
|
+
routes.splice(routes.findIndex(([route_parts]) => {
|
|
811
|
+
if (route_parts.length !== path_parts.length)
|
|
812
|
+
return false;
|
|
813
|
+
|
|
814
|
+
for (let i = 0; i < route_parts.length; i++) {
|
|
815
|
+
if (route_parts[i] !== path_parts[i])
|
|
816
|
+
return false;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
return true;
|
|
820
|
+
}, 1));
|
|
821
|
+
},
|
|
822
|
+
|
|
807
823
|
/** Serve a directory for a specific route. */
|
|
808
824
|
dir: (path: string, dir: string, handler?: DirHandler, method: HTTP_METHODS = 'GET'): void => {
|
|
809
825
|
if (path.endsWith('/'))
|