New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@moveyourdigital/router

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@moveyourdigital/router

Allows to match any part of the HTTP request message

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

RegexRouter

Unlike traditional routers that only match the path and method, RegexRouter allows to match any part of the HTTP request message, which includes headers, method, path, URL and query parameters, enabling customized and dynamic routing logic.

Notice: currently available in beta; avoid using in production.

Key Features

  • Match Any Part of the Request: Goes beyond the basics of path and method matching: routes can be regex-based on headers, query strings, cookies, and more.

  • Flexible: Provides and allows extension with middlewares and uses standard Web API syntax.

  • Easy to Use: Plugin to any environment. It support's node.js, browser, edge, workers, etc.

  • High Performance: Being small and straighforward, it is optimized for speed and efficiency to handle high traffic loads without compromising on routing capabilities.

Getting Started

Installation

Install RegexRouter via npm:

npm install @moveyourdigital/router

Basic Usage

import { createServer } from "http"
import { bind } from "@moveyourdigital/router/node"
import { Router } from "@moveyourdigital/router"
import { auth, logger, notFound, throwable } from "@moveyourdigital/router"

const router = new Router()
  .add(/.*/, logger(), throwable(), notFound())
  .add(/^POST/, () => new Response())
  .add(/^GET \/private\s/, auth({ secret: 'test' }), () => new Response())
  .add(/^GET \/(.*\n)+user-agent: (?<agent>.*)/i, (req, ctx) => {
    return Response.json(`Hello ${ctx.params?.get('agent')}`, {
      status: 201
    })
  })

bind(createServer, router).listen(3001) // bind for Node JS createServer

Development

To watch for changes in src directory.

npm start

To bundle for production

npm run build

Unit tests are located in

npm t

Contributions

This project is open to contributions. Feel free to discuss in Issues any implementation details first.

Keywords

FAQs

Package last updated on 06 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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