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 2.0.1 to 2.0.2

8

lib/index.js

@@ -18,4 +18,8 @@ const { getParamsAndQuery } = require('../utils')

exports.router = (...funcs) => async (req, res) =>
funcs.map(fn => fn(req, res)).find(fn => fn)
exports.router = (...funcs) => async (req, res) => {
for (const fn of funcs) {
const result = await fn(req, res)
if (result || res.headersSent) return result
}
}

@@ -22,0 +26,0 @@ METHODS.forEach(method => {

@@ -68,2 +68,32 @@ const test = require('ava')

test('multiple matching routes', async t => {
const withPath = () => 'Hello world'
const withParam = () => t.fail('Clashing route should not have been called')
const routes = router(
get('/path', withPath),
get('/:param', withParam)
)
const url = await server(routes)
const pathResponse = await request(`${url}/path`)
t.is(pathResponse, 'Hello world')
})
test('multiple matching async routes', async t => {
const withPath = (req, res) => micro.send(res, 200, 'Hello world')
const withParam = () => t.fail('Clashing route should not have been called')
const routes = router(
get('/path', withPath),
get('/:param', withParam)
)
const url = await server(routes)
const pathResponse = await request(`${url}/path`)
t.is(pathResponse, 'Hello world')
})
test('error without path and handler', async t => {

@@ -70,0 +100,0 @@ const fn = () => {

{
"name": "microrouter",
"description": "🚉 A tiny and functional router for Zeit's Micro",
"version": "2.0.1",
"version": "2.0.2",
"main": "lib/index.js",

@@ -32,3 +32,4 @@ "scripts": {

"object-curly-spacing": 0,
"unicorn/explicit-length-check": 0
"unicorn/explicit-length-check": 0,
"no-await-in-loop": 0
}

@@ -35,0 +36,0 @@ },

@@ -31,3 +31,3 @@ :station: _**Micro Router -**_ A tiny and functional router for Zeit's [micro](https://github.com/zeit/micro)

const notfound = () =>
const notfound = (req, res) =>
send(res, 404, 'Not found route')

@@ -34,0 +34,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