New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@dashdot/router

Package Overview
Dependencies
Maintainers
6
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dashdot/router

A simple and functional native Node router with some helpers.

latest
npmnpm
Version
1.0.3
Version published
Maintainers
6
Created
Source

Dashdot Router

build codecov

A simple and functional Node router with some helpers.

Usage

Inside your Node project directory, run the following:

npm i --save @dashdot/router

Or with Yarn:

yarn add @dashdot/router

API

import { createServer } from 'http'
import { createRouter, get, post, put, del, all, ok, notFound } from '@dashdot/router'

const { PORT, HOST } = process.env

const server = createServer(createRouter(
    get('/posts/:id', (req, res) => ok(res, req.params.id)),
    post('/posts/:id', (req, res) => ok(res, req.params.id)),
    put('/posts/:id', (req, res) => ok(res, req.params.id)),
    del('/posts/:id', (req, res) => ok(res, req.params.id)),
    all('/*', (req, res) => notFound(res)),
))

server.listen(PORT, HOST, () => {
    console.log(`Server started and listening on http://${HOST}:${PORT}`)
})

Cross-Origin Resource Sharing

const cors = createCors({
    allowMethods: ['GET'],
    extendAllowHeaders: ['trace']
})

const server = createServer(createRouter(
    get('/posts', (req, res) => cors(ok(res))),
))

Rate limiting

const rateLimit = createRateLimit({
    window: 1000, // 1 sec
    limit: 10, // 10 requests
})

const server = createServer(createRouter(
    get('/posts', (req, res) => rateLimit(ok(res))),
))

FAQs

Package last updated on 24 Aug 2023

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