Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

microrouter

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

microrouter - npm Package Compare versions

Comparing version 3.1.1 to 3.1.2

2

package.json
{
"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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc