Skip to content

Commit 3bc8ae2

Browse files
committed
Updated readme and types
1 parent 2d6727e commit 3bc8ae2

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,29 @@ router.addRoute('/test/:param([a-z]+)', function(req, res, url) { // Route with
2626
res.end('Parameter value: ' + param);
2727
});
2828

29+
router.get('/test/get/method', function(req, res, url) { // Route that only accepts get requests
30+
31+
res.writeHead(200, { 'Content-Type': 'text/html' });
32+
res.end('Test get method only');
33+
});
34+
35+
router.post('/test/get/method', function(req, res, url) { // Route that only accepts post requests
36+
37+
res.writeHead(200, { 'Content-Type': 'text/html' });
38+
res;.end('Test post method only');
39+
});
40+
41+
router.put('/test/put/method', function(req, res, url) { // Route that only accepts put requests
42+
43+
res.writeHead(200, { 'Content-Type': 'text/html' });
44+
res.end('Test put method only');
45+
});
46+
47+
router.delete('/test/delete/method', function(req, res, url) { // Route that only accepts delete requests
48+
49+
res.writeHead(200, { 'Content-Type': 'text/html' });
50+
res.end('Test delete method only');
51+
});
2952

3053
router.listen(3000, function() { // Set port for router/server to listen to
3154
console.log("Server listening on port 3000");

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "small-router",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "Small router module that creates http server and runs callbacks that have have been added for a route via the api",
55
"main": "index.js",
66
"scripts": {

small-router.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type parseDataCB = (
2121
export class Router {
2222
prefix: string;
2323
constructor();
24-
addRoute(route: string | string[], cb: addRouteCB): boolean;
24+
addRoute(route: string | string[], cb: addRouteCB, method?: string): boolean;
2525
addAssetPath(
2626
asset: string,
2727
path: string,
@@ -40,6 +40,10 @@ export class Router {
4040
parseURLParameter(urlPart: string, routePart: string): string | false;
4141
pageNotFound(res: http.ServerResponse, url: string): void;
4242
close(): void;
43+
get(route: string | string[], cb: addRouteCB);
44+
post(route: string | string[], cb: addRouteCB);
45+
put(route: string | string[], cb: addRouteCB);
46+
delete(route: string | string[], cb: addRouteCB);
4347
}
4448

4549
export default function smallRouter(http: typeof import("http")): Router;

0 commit comments

Comments
 (0)