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

@rubynetwork/rammerhead

v1.3.2

Published

Easily use and run Rammerhead

Downloads

987

Readme

Rammerhead Package

  • Easily consume and use Rammerhead server side

CLI

  • Fires up a standalone server for Rammerhead
npx @rubynetwork/rammerhead

Flags:

  • -ho, --host <host> - Listen on a specific host (default: 0.0.0.0)
  • -p, --port <port> - The port to listen on (default: 8080)
  • -l, --loglevel <loglevel> - Change the log level (default: debug) [options: disabled, debug, traffic, info, warn, error]
  • -rp, --reverseproxy - Whether or not the server is behind a reverse proxy. (default: false)
  • -h, --help - Show this same type of info

Usage:

  • Basic server (import required items):
import { createRammerhead, shouldRouteRh, routeRhUpgrade, routeRhRequest } from '@rubynetwork/rammerhead';

const rh = createRammerhead({
    logLevel: 'debug', //Options are: disabled, debug, traffic, info, warn, error (default: debug)
    reverseProxy: false, //whether or not this server is running behind a reverse proxy (default: false)
    disableLocalStorageSync: false, //disable localstorage sync (not recommended) (default: false)
    disableHttp2: false //disable http2 usage (default: false) (NOT RECOMMENDED)
})

const server = http.createServer();
server.on('request', (req, res) => {
    if (shouldRouteRh(req)) {
        routeRhRequest(rh /* from the createRammerhead function MUST be passed */, req, res)
    }
})
server.on('upgrade', (req, socket, head) => {
    if (shouldRouteRh(req)) {
        routeRhUpgrade(rh /* from the createRammerhead funtion MUST be passed */, req, socket, head)
    }
})
server.listen({host: '0.0.0.0', port: 8080}, () => {
    console.log('Server is listening on port 8080!');
})
  • Basic server (default export):
import rammerhead from '@rubynetwork/rammerhead';

const rh = rammerhead.createRammerhead({
    logLevel: 'debug', //Options are: disabled, debug, traffic, info, warn, error (default: debug)
    reverseProxy: false, //whether or not this server is running behind a reverse proxy (default: false)
    disableLocalStorageSync: false, //disable localstorage sync (not recommended) (default: false)
    disableHttp2: false //disable http2 usage (default: false) (NOT RECOMMENDED)
})

const server = http.createServer();
server.on('request', (req, res) => {
    if (rammerhead.shouldRouteRh(req)) {
        rammerhead.routeRhRequest(rh /* from the createRammerhead function MUST be passed */, req, res)
    }
})
server.on('upgrade', (req, socket, head) => {
    if (rammerhead.shouldRouteRh(req)) {
        rammerhead.routeRhUpgrade(rh /* from the createRammerhead funtion MUST be passed */, req, socket, head)
    }
})
server.listen({host: '0.0.0.0', port: 8080}, () => {
    console.log('Server is listening on port 8080!');
})
  • Express:
import express from "express";
import { createServer } from "node:http";
import { createRammerhead, shouldRouteRh, routeRhUpgrade, routeRhRequest } from '@rubynetwork/rammerhead';

const app = express();
const server = createServer();
const rh = rammerhead.createRammerhead({
    logLevel: 'debug', //Options are: disabled, debug, traffic, info, warn, error (default: debug)
    reverseProxy: false, //whether or not this server is running behind a reverse proxy (default: false)
    disableLocalStorageSync: false, //disable localstorage sync (not recommended) (default: false)
    disableHttp2: false //disable http2 usage (default: false) (NOT RECOMMENDED)
})

server.on("request", (req, res) => {
  res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
  res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
  if (shouldRouteRh(req)) {
    routeRhRequest(rh /* from the createRammerhead function MUST be passed */, req, res)
  }
  else {
    app(req, res);
  }
});
server.on("upgrade", (req, socket, head) => {    
    if (rammerhead.shouldRouteRh(req)) {
        rammerhead.routeRhUpgrade(rh /* from the createRammerhead funtion MUST be passed */, req, socket, head)
    }
    else {
        socket.end()
    }
});

server.on("listening", () => {
  console.log("Listening on: http://localhost:8080");
});

server.listen({port: 8080});
  • Fastify:
import Fastify from 'fastify';
import { createServer } from 'node:http';
import { createRammerhead, shouldRouteRh, routeRhUpgrade, routeRhRequest } from '@rubynetwork/rammerhead';

const rh = rammerhead.createRammerhead({
    logLevel: 'debug', //Options are: disabled, debug, traffic, info, warn, error (default: debug)
    reverseProxy: false, //whether or not this server is running behind a reverse proxy (default: false)
    disableLocalStorageSync: false, //disable localstorage sync (not recommended) (default: false)
    disableHttp2: false //disable http2 usage (default: false) (NOT RECOMMENDED)
})

const serverFactory = (handler) => {
  return createServer()
    .on('request', (req, res) => {
      if (shouldRouteRh(req)) {
        routeRhRequest(rh /* from the createRammerhead function MUST be passed */, req, res)
      }
      else {
          handler(req, res);
      }
    })
    .on('upgrade', (req, socket, head) => {
      if (shouldRouteRh(req)) {
        routeRhUpgrade(rh /* from the createRammerhead funtion MUST be passed */, req, socket, head)
      }
    });
};

const app = Fastify({ logger: false, serverFactory: serverFactory });

app.listen({ port: 8080, host: '0.0.0.0' });
console.log('Server is listening on: http://localhost:8080.');