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

@routup/cors

v2.0.0

Published

CORS plugin for routup.

Readme

@routup/cors

npm version main codecov Known Vulnerabilities Conventional Commits

A CORS plugin for routup — handles preflight (OPTIONS) requests and adds Access-Control-* response headers.

Table of Contents

Installation

npm install @routup/cors --save

Documentation

To read the docs, visit https://routup.net

Usage

Mount the plugin once at the top of the router. It both adds CORS headers to ordinary responses and short-circuits preflight OPTIONS requests with a 204.

import { App, defineCoreHandler, serve } from 'routup';
import { cors } from '@routup/cors';

const router = new App();

router.use(cors({
    origin: ['https://app.example.com'],
    credentials: true,
    allowHeaders: ['content-type', 'authorization'],
}));

router.get('/', defineCoreHandler(() => 'ok'));

serve(router, { port: 3000 });

Options

| Option | Type | Default | Description | |---|---|---|---| | origin | boolean \| string \| RegExp \| (string \| RegExp)[] \| (origin) => boolean | '*' | Value of Access-Control-Allow-Origin. true reflects the request origin (credentials-friendly); false skips CORS entirely. A bare string is emitted verbatim ('*', 'null', or any concrete origin). A RegExp / array / function reflects the request origin on match. | | methods | '*' \| string[] | '*' | Value of Access-Control-Allow-Methods on preflight. | | allowHeaders | '*' \| string[] | '*' | Value of Access-Control-Allow-Headers on preflight. When '*' or empty, mirrors the request's Access-Control-Request-Headers. | | exposeHeaders | '*' \| string[] | '*' | Value of Access-Control-Expose-Headers. | | credentials | boolean | false | Sets Access-Control-Allow-Credentials: true. With credentials, the browser treats a literal '*' as a non-wildcard value: a '*' origin or methods causes the request to be blocked, and '*' exposeHeaders silently hides custom response headers from JavaScript. Use origin: true to reflect the request origin (credentials-safe), enumerate methods explicitly, and list the response headers you want exposed. allowHeaders: '*' is fine — the plugin mirrors Access-Control-Request-Headers so * never appears on the wire. | | maxAge | string \| number \| false | false | Value of Access-Control-Max-Age on preflight, in seconds. Numbers are stringified. | | preflight.continue | boolean | false | When true, sets the preflight headers and calls event.next() instead of returning a 204 — lets your own OPTIONS handler take over. | | preflight.status | number | 204 | Status code returned for preflight responses. Preflight responses also set Content-Length: 0 for Safari compatibility. |

Helpers

handleCors

All-in-one helper: appends headers and, on a preflight request, returns the preflight Response. Useful inside an existing handler when you don't want to install the plugin globally.

declare function handleCors(
    event: IAppEvent,
    options: Options,
): Response | undefined;
router.all('/', defineCoreHandler((event) => {
    const corsResponse = handleCors(event, { origin: '*' });
    if (corsResponse) {
        return corsResponse;
    }
    // your handler logic
    return 'ok';
}));

appendCorsHeaders

Appends the standard Access-Control-Allow-* and Access-Control-Expose-Headers to the current response. No-op on preflight detection — pair with appendCorsPreflightHeaders if you handle preflight yourself.

declare function appendCorsHeaders(
    event: IAppEvent,
    options: Options,
): void;

appendCorsPreflightHeaders

Appends the preflight set (Access-Control-Allow-Methods, Access-Control-Allow-Headers, Access-Control-Max-Age, etc.) to event.response.headers. Caller is responsible for returning a Response.

declare function appendCorsPreflightHeaders(
    event: IAppEvent,
    options: Options,
): void;

isPreflightRequest

Returns true when the request is OPTIONS with both an Origin header and an Access-Control-Request-Method header.

declare function isPreflightRequest(event: IAppEvent): boolean;

isCorsOriginAllowed

Pure helper that evaluates the origin option against an origin string. Useful for custom decisions outside the plugin.

declare function isCorsOriginAllowed(
    origin: string | null | undefined,
    options: Options,
): boolean;

License

Made with 💚

Published under MIT License.