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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@superpilot/pages

v0.0.1-alpha.0

Published

Middleware to add Superpilot pages to Node.js servers

Readme

@superpilot/pages

Node.js middleware for adding Superpilot pages to your e-commerce website.

Install

npm install @superpilot/pages

Quick Start

With Express.js

import { createExpressProxy } from '@superpilot/pages';
import express from 'express';

const superpilot = createExpressProxy({
  origin: 'https://acme-prd.pages.superpilot.ai',
});

const app = express();
// /products/* → proxies to → https://acme-prd.pages.superpilot.ai/products/*
app.use('/products/*', superpilot.proxy);

app.listen(3000);

With Native Node.js http

import { createProxy } from '@superpilot/pages';
import http from 'http';

const superpilot = createProxy({
  origin: 'https://acme-prd.pages.superpilot.ai',
});

const server = http.createServer((req, res) => {
  superpilot.proxy({
    req,
    res,
    next: (err) => {
      if (err) {
        res.statusCode = 500;
        res.end(err.message);
      }
    },
  });
});

server.listen(3000);

Usage Patterns

1. Proxy All Requests (Dynamic Paths)

The proxy function forwards requests with their original path:

const superpilot = createExpressProxy({
  origin: 'https://acme-prd.pages.superpilot.ai',
});

app.use('/products/*', superpilot.proxy);

Request to /products/sale?color=red → proxies to https://acme-prd.pages.superpilot.ai/products/sale?color=red

2. Proxy to a Fixed Page

The proxyTo function always proxies to the same Superpilot page, regardless of the incoming path:

const superpilot = createExpressProxy({
  origin: 'https://acme-prd.pages.superpilot.ai',
});

// Both routes serve the same Superpilot page
app.use('/landing', superpilot.proxyTo('/products/promo'));
app.use('/special-offer', superpilot.proxyTo('/products/promo'));

Both /landing and /special-offer → proxy to https://acme-prd.pages.superpilot.ai/products/promo

3. Multiple Superpilot Origins

const staging = createExpressProxy({
  origin: 'https://acme-staging.pages.superpilot.ai',
});

const production = createExpressProxy({
  origin: 'https://acme-prd.pages.superpilot.ai',
});

app.use('/preview/*', staging.proxy);
app.use('/products/*', production.proxy);

4. Content Security Policy (CSP)

Superpilot pages require specific CSP directives:

const superpilot = createExpressProxy({
  origin: 'https://acme-prd.pages.superpilot.ai',
});

const baseCSP = {
  'default-src': ["'self'"],
  'style-src': ["'self'", "'unsafe-inline'"],
};

const mergedCSP = superpilot.mergeCSP(baseCSP);

app.use((req, res, next) => {
  const cspString = Object.entries(mergedCSP)
    .map(([key, values]) => `${key} ${values.join(' ')}`)
    .join('; ');
  res.setHeader('Content-Security-Policy', cspString);
  next();
});

Configuration

Environment Variables

  • SUPERPILOT_ORIGIN - Superpilot pages URL (overrides origin option)

Priority: SUPERPILOT_ORIGIN env var > origin option

Advanced Usage

Custom Fetch

import { createExpressProxy } from '@superpilot/pages';

async function fetchWithRetry(url: string, options: RequestInit): Promise<Response> {
  const maxRetries = 3;
  for (let i = 0; i < maxRetries; i++) {
    try {
      const response = await fetch(url, options);
      if (response.ok || i === maxRetries - 1) return response;
      if (response.status >= 500) {
        continue;
      }
      return response;
    } catch (err) {
      if (i === maxRetries - 1) throw err;
    }
  }
  throw new Error('Max retries reached');
}

const superpilot = createExpressProxy({
  origin: 'https://acme.pages.superpilot.ai',
  fetch: fetchWithRetry,
});

Custom Framework Adapters

For frameworks other than Express or Node.js http, provide custom adapters:

import { createProxy } from '@superpilot/pages';

// Example: Fastify adapters
const fastifyAdapters = {
  request: {
    getUrl: ({ req }) => req.url,
    getMethod: ({ req }) => req.method,
    getHeader: ({ req, name }) => req.headers[name],
    getBody: ({ req }) => req.raw,
  },
  response: {
    setStatus: ({ reply, status }) => reply.status(status),
    setHeader: ({ reply, name, value }) => reply.header(name, value),
    // ... other methods
  },
};

const superpilot = createProxy({
  origin: 'https://acme-prd.pages.superpilot.ai',
  requestAdapter: fastifyAdapters.request,
  responseAdapter: fastifyAdapters.response,
});

Development

pnpm build
pnpm test
pnpm typecheck
pnpm lint
pnpm test:proxy -- --origin https://example.com

License

MIT