Skip to content

Commit 64b425f

Browse files
committed
fix dependency
1 parent d7fa030 commit 64b425f

File tree

6 files changed

+43
-11
lines changed

6 files changed

+43
-11
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ install:
1010
- pnpm install
1111

1212
script:
13-
- |
14-
pnpm run test && pnpm run lint && pnpm run build
13+
- pnpm run precommit
1514

1615
deploy:
1716
- provider: npm
1817
edge: true
18+
# leave dist directory
1919
skip_cleanup: true
2020
api_key:
2121
secure: GuZ4V8x2m2GtduukJh3rpaezIplvjOcsUy14fui1XrC3tQy5w52cQvl/04tqWyWNCdxTTQttENaH4POY6hG/5192BhPFNkzBW8k6luL2ktWt+DWMWMwtdnt9ex0X+LDHKNyoMZ+YgrOwPaV4UcxTDG8K7+0Q3yDrIJaN4VQJNLm1iT4CRJUibHf6fhHXYbCk0Tr1niy1tNPog1kkFUEr3D4hy86WbuuBdp3m4QhEaqKZkbfyjZoSKlCAZtBL5bjbTLA7h5GZQFqsT2vR9quUwFy7Xo/3wFWEfdJyoxgrlnU1QZt1WVfDx6iMRImOA0O9u3mm0FMm4J9yAUdzuZq+47iapJSpyC2ctzEIrLdrgnXUrklLVl10xEMEGHtdPKJ5a31KG3iXfO7ENfLRNXY+1IqTKaLCjMjpCR0TRO5zvL3K5Zn4tHaU343FKowKmnhKWBFveGb66dmSM2QslaULYvB1AWLDsc2fwrbsSocpjmK3Ab5RzU1PG73Yv65i6u70tpTFDAj3+uICEjzbreMhvzl6QSOdFBGrCRn7R6/zaRL4pNX/H2AZlTIDP9D2XaFQC0B02H1+1u34ybFogR624UXFK8i28Cu/ei6tgjrFZjcJBl+LVfBiA0N56cnYpU3yqO/jat89f6vunwMPCYC7kb6cI90Cx3GoUOQtzJvNL/I=

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,34 @@ This router is intended to be used with native node http interface. Features:
2020
- Can be used with [path-to-regexp](https://github.com/pillarjs/path-to-regexp).
2121
- Work with another servers? Tell it me!
2222

23+
First example with micro
24+
------------------------
25+
```typescript
26+
// specify default handler
27+
const router = new Router((req, res) => sendError(req, res, { statusCode: 404 }))
28+
29+
router.addRoute({
30+
matcher: new ExactUrlPathnameMatcher(['/hello']),
31+
handler: () => 'Hello kitty!',
32+
})
33+
34+
35+
const [address, port] = ['localhost', 8080]
36+
http.createServer(micro(router.serve)).listen(port, address)
37+
```
38+
39+
40+
Installation
41+
------------
42+
43+
Choose for one of your favourite package manager:
44+
45+
```bash
46+
pnpm install @bessonovs/node-http-router
47+
npm install @bessonovs/node-http-router
48+
yarn add @bessonovs/node-http-router
49+
```
50+
2351
License
2452
-------
2553

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
"lint": "eslint . --ext .ts,.js",
3030
"build": "tsc",
3131
"example-node-start": "tsc && node dist/examples/node.js",
32-
"example-micro-start": "tsc && node dist/examples/micro.js"
32+
"example-micro-start": "tsc && node dist/examples/micro.js",
33+
"precommit": "$_ run test && $_ run lint && $_ run build"
3334
},
3435
"dependencies": {
35-
"fast-url-parser": "1.1.3"
36+
"fast-url-parser": "1.1.3",
37+
"ts-toolbelt": "4.8.19"
3638
},
3739
"devDependencies": {
3840
"@types/express": "4.17.1",
@@ -50,7 +52,6 @@
5052
"node-mocks-http": "1.8.0",
5153
"path-to-regexp": "3.1.0",
5254
"ts-jest": "24.1.0",
53-
"ts-toolbelt": "4.8.19",
5455
"typescript": "3.6.4"
5556
},
5657
"publishConfig": {

src/examples/micro.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import http from 'http'
2-
import micro from 'micro'
2+
import micro, { sendError } from 'micro'
33
import { Router } from '../router'
44
import { EndpointMatcher } from '../matchers/EndpointMatcher'
55
import { ExactUrlPathnameMatcher } from '../matchers'
@@ -16,7 +16,7 @@ yarn example-micro-start
1616
1717
*/
1818

19-
const router = new Router(() => 'not found')
19+
const router = new Router((req, res) => sendError(req, res, { statusCode: 404 }))
2020

2121
const [address, port] = ['localhost', 8080]
2222

src/examples/node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ yarn example-node-start
1616
*/
1717

1818
const router = new Router((req, res) => {
19-
res.write('not found')
19+
res.statusCode = 404
2020
res.end()
2121
})
2222

src/matchers/__tests__/AndMatcher.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import {
77
it('none match', () => {
88
const result = new AndMatcher([
99
new MethodMatcher(['POST']),
10-
new MethodMatcher(['POST']),
11-
])
12-
.match(httpMocks.createRequest(), httpMocks.createResponse())
10+
new ExactUrlPathnameMatcher(['/test']),
11+
]).match(httpMocks.createRequest(), httpMocks.createResponse())
12+
1313
expect(result).toStrictEqual({
1414
matched: false,
1515
})
@@ -20,6 +20,7 @@ it('first match, second not', () => {
2020
new MethodMatcher(['GET']),
2121
new ExactUrlPathnameMatcher(['/test']),
2222
]).match(httpMocks.createRequest(), httpMocks.createResponse())
23+
2324
expect(result).toStrictEqual({
2425
matched: false,
2526
})
@@ -35,6 +36,7 @@ it('first not match, but second', () => {
3536
new MethodMatcher(['GET']),
3637
new ExactUrlPathnameMatcher(['/test']),
3738
]).match(request, httpMocks.createResponse())
39+
3840
expect(result).toStrictEqual({
3941
matched: false,
4042
})
@@ -49,6 +51,7 @@ it('both match', () => {
4951
new MethodMatcher(['GET']),
5052
new ExactUrlPathnameMatcher(['/test']),
5153
]).match(request, httpMocks.createResponse())
54+
5255
expect(result).toStrictEqual({
5356
matched: true,
5457
and: [

0 commit comments

Comments
 (0)