npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@qpoint/router

v0.2.1

Published

Qpoint - an intelligent edge router framework

Downloads

8

Readme

Qpoint

Intelligence at the edge - an edge router framework

Compose powerful edge capabilities to analyze, transform, reject, or proxy traffic as it passes through the edge to your apps.

Designed to run within worker runtimes, a qpoint router can be deployed trivially to edge networks like Cloudflare Workers and Deno Deploy, or with the help of Qpoint, deploy to any platform including your own servers.

Example

import Router from '@qpoint/router'
import proxy from '@qpoint/proxy'
import maskUrls from '@qpoint/mask-urls'
import replaceContent from '@qpoint/replace-content'
import rewriteHtml from '@qpoint/rewrite-html'

// initialize and export the router
export default new Router()

  // proxy request to app
  .use(proxy({ appUrl:"https://qdemo.io" }))

  // mask urls in html response
  .use(maskUrls())

  // replace occurrences of qdemo with qpoint
  .use(replaceContent({ rules: [{ from: 'qdemo', to: 'qpoint' }] }))

  // rewrite html (trigger htmlrewriter rules)
  .use(rewriteHtml())

Composable adapters

Adapters are middleware functions to be executed in a chain, each potentially modifying the request/response until finally returning the response.

Example: Reject the request (at the edge) if no auth is provided

router.use((ctx: Context, next: Function) => {
  
  // check for the Authorization header
  if (!ctx.request.headers.has("Authorization")) {
    // set the response to unauthorized
    ctx.response = new Response(null, { status: 401 });

    // return without calling next() to terminate the chain
    return
  }

  // continue the chain to the next
  return next();
})

Context, Request and Response

Each adapter receives a Qpoint Context object that wraps an incoming request and the corresponding response. ctx is often used as the parameter name for the context object.

router.use(async (ctx: Context, next: Function) => { await next(); });

After each of the adapters have run, the response as set on the context will be returned.

Proxies and Load Balancers

A very common case for Qpoint is building intelligent proxies and load balancers, and since the original Request object cannot be modified, the proxy is a copy of the original request that can be fetched by a proxy or load-balancer adapter.

In such a scenario, adapters that need to modify the request before a proxy fetch occurs will sequencially modify or replace the proxy instance as the chain progresses.