Skip to content

Commit

Permalink
Updated readme and types
Browse files Browse the repository at this point in the history
  • Loading branch information
SC7639 committed Sep 14, 2020
1 parent 2d6727e commit 3bc8ae2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ router.addRoute('/test/:param([a-z]+)', function(req, res, url) { // Route with
res.end('Parameter value: ' + param);
});

router.get('/test/get/method', function(req, res, url) { // Route that only accepts get requests

res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('Test get method only');
});

router.post('/test/get/method', function(req, res, url) { // Route that only accepts post requests

res.writeHead(200, { 'Content-Type': 'text/html' });
res;.end('Test post method only');
});

router.put('/test/put/method', function(req, res, url) { // Route that only accepts put requests

res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('Test put method only');
});

router.delete('/test/delete/method', function(req, res, url) { // Route that only accepts delete requests

res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('Test delete method only');
});

router.listen(3000, function() { // Set port for router/server to listen to
console.log("Server listening on port 3000");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "small-router",
"version": "1.2.0",
"version": "1.2.1",
"description": "Small router module that creates http server and runs callbacks that have have been added for a route via the api",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion small-router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type parseDataCB = (
export class Router {
prefix: string;
constructor();
addRoute(route: string | string[], cb: addRouteCB): boolean;
addRoute(route: string | string[], cb: addRouteCB, method?: string): boolean;
addAssetPath(
asset: string,
path: string,
Expand All @@ -40,6 +40,10 @@ export class Router {
parseURLParameter(urlPart: string, routePart: string): string | false;
pageNotFound(res: http.ServerResponse, url: string): void;
close(): void;
get(route: string | string[], cb: addRouteCB);
post(route: string | string[], cb: addRouteCB);
put(route: string | string[], cb: addRouteCB);
delete(route: string | string[], cb: addRouteCB);
}

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

0 comments on commit 3bc8ae2

Please sign in to comment.