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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@solumjs/middlewares

v0.3.5

Published

SolumJS middlewares: security headers, CORS, rate limit, logging, error handling

Readme

@solumjs/middlewares

Security headers, CORS, rate limiting, CSRF protection, error handling, and @ControllerAdvice.

Install

npm install @solumjs/middlewares

Security Middleware

import { createSecurityMiddlewares, requestLogger, errorHandler, notFoundHandler } from "@solumjs/middlewares";

// Apply all security middleware at once (security headers + CORS + rate limiting)
app.use(createSecurityMiddlewares());

// Request logging
app.use(requestLogger());

// Global error handler
app.use(errorHandler());

// 404 handler (use as last middleware)
app.use(notFoundHandler());

createSecurityMiddlewares

Applies 3 middleware in order:

  1. Security headers — CSP, HSTS, X-Frame-Options, etc.
  2. CORS — reads CORS_ORIGIN from env
  3. Rate limiting — reads RATE_LIMIT_MAX from env (default 100 per 15 min)
app.use(createSecurityMiddlewares());

CORS

Configured via CORS_ORIGIN environment variable.

# .env
CORS_ORIGIN=https://myapp.com
RATE_LIMIT_MAX=200

Rate Limiting

import { createRateLimit } from "@solumjs/middlewares";

app.use(createRateLimit({ windowMs: 15 * 60 * 1000, max: 100 }));

Redis Rate Limiting (Distributed)

import { createRedisRateLimit } from "@solumjs/middlewares";

const redisClient = await connectRedis({ url: "redis://localhost:6379" });

app.use(createRedisRateLimit({
    redis: redisClient,
    windowMs: 60000,
    max: 100,
    keyPrefix: "api:",         // optional
    trustProxy: true,          // optional, uses X-Forwarded-For
}));

CSRF Protection

import { csrfProtection } from "@solumjs/middlewares";

// secret is required (min 32 chars) — uses timing-safe comparison
app.use(csrfProtection({ secret: process.env.CSRF_SECRET }));

// With custom options
app.use(csrfProtection({
    secret: process.env.CSRF_SECRET,
    cookieName: "csrf-token",
    headerName: "x-csrf-token",
    ttlSeconds: 3600,
    sameSite: "lax",
    secure: true,
    ignoreMethods: ["GET", "HEAD", "OPTIONS"],
}));

@ControllerAdvice (Global Error Handling)

import { ControllerAdvice, ExceptionHandler } from "@solumjs/middlewares";
import { SolumjsRequest } from "@solumjs/http";
import { NotFoundException, BadRequestException } from "@solumjs/core";

@ControllerAdvice
export class GlobalExceptionAdvice {

    @ExceptionHandler(NotFoundException)
    handleNotFound(err: NotFoundException, req: SolumjsRequest) {
        req.log?.warn({ path: req.path }, err.message);
        return { status: "error", code: "NOT_FOUND", message: err.message };
    }

    @ExceptionHandler(BadRequestException)
    handleBadRequest(err: BadRequestException, req: SolumjsRequest) {
        return { status: "error", code: "BAD_REQUEST", message: err.message };
    }

    @ExceptionHandler(Error)
    handleGeneric(err: Error, req: SolumjsRequest) {
        req.log?.error({ path: req.path, err }, "Unhandled error");
        return { status: "error", code: "INTERNAL_ERROR", message: "Internal server error" };
    }
}

Security Headers

Applied by createSecurityMiddlewares():

| Header | Value | |--------|-------| | content-security-policy | default-src 'self'; ... | | cross-origin-opener-policy | same-origin | | cross-origin-resource-policy | same-origin | | strict-transport-security | max-age=31536000; includeSubDomains | | x-content-type-options | nosniff | | x-frame-options | SAMEORIGIN | | x-xss-protection | 0 | | referrer-policy | strict-origin-when-cross-origin |

License

MIT