Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rubynetwork/rammerhead

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rubynetwork/rammerhead

Easily use and run Rammerhead

  • 1.3.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
246
decreased by-19.34%
Maintainers
0
Weekly downloads
 
Created
Source

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.');

Keywords

FAQs

Package last updated on 18 Nov 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