microrouter
Advanced tools
Comparing version 3.1.1 to 3.1.2
{ | ||
"name": "microrouter", | ||
"description": "🚉 A tiny and functional router for ZEIT's Micro", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"main": "dist/lib/index.js", | ||
@@ -6,0 +6,0 @@ "jsnext:main": "src/lib/index.js", |
@@ -10,3 +10,3 @@ :station: _**Micro Router -**_ A tiny and functional router for ZEIT's [micro](https://github.com/zeit/micro) | ||
* **Tiny**. Just 23 lines of code. | ||
* **Tiny**. Just couple lines of code. | ||
* **Functional**. Write your http methods using functions. | ||
@@ -71,3 +71,3 @@ * **Async**. Design to use with `async/await` | ||
The `handler` method is a simple function that will make some action base on your path. | ||
The format of this function is `(res, res) => {}` | ||
The format of this function is `(req, res) => {}` | ||
@@ -74,0 +74,0 @@ ##### `req.params` |
@@ -6,10 +6,11 @@ const UrlPattern = require('url-pattern') | ||
const methodFn = method => (path, handler) => { | ||
if (!path) throw new Error('You need to set a valid path') | ||
const methodFn = method => (givenPath, handler) => { | ||
if (!givenPath) throw new Error('You need to set a valid path') | ||
if (!handler) throw new Error('You need to set a valid handler') | ||
return (req, res, namespace) => { | ||
const route = !isPattern(path) | ||
? new UrlPattern(`${namespace}${path}`, patternOpts) | ||
: path | ||
const path = givenPath === '/' ? '(/)' : givenPath | ||
const route = isPattern(path) | ||
? path | ||
: new UrlPattern(`${namespace}${path}`, patternOpts) | ||
@@ -16,0 +17,0 @@ const { params, query } = getParamsAndQuery(route, req.url) |
@@ -180,1 +180,23 @@ const { Readable } = require('stream') | ||
}) | ||
test('route with namespace without trailing slash', async t => { | ||
const fooRoutes = withNamespace('/foo') | ||
const routes = router(fooRoutes(get('/', () => 'foo'))) | ||
const url = await server(routes) | ||
const fooResponse = await request(`${url}/foo`) | ||
t.is(fooResponse, 'foo') | ||
}) | ||
test('route with namespace with trailing slash', async t => { | ||
const fooRoutes = withNamespace('/foo') | ||
const routes = router(fooRoutes(get('/', () => 'foo'))) | ||
const url = await server(routes) | ||
const fooResponse = await request(`${url}/foo/`) | ||
t.is(fooResponse, 'foo') | ||
}) |
@@ -6,2 +6,3 @@ const { parse } = require('url') | ||
segmentNameCharset: 'a-zA-Z0-9_-', | ||
segmentValueCharset: 'a-zA-Z0-9@.+-_', | ||
} | ||
@@ -8,0 +9,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18820
257