Packages

CORS Package

This package provides first-party support for Cross-Origin Resource Sharing (https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS).

Installation

To start using the package, simply install into an existing Raptor application with your package manager.

deno add npm:@raptor-js/cors
bun add @raptor-js/cors
npm install @raptor-js/cors
yarn add @raptor-js/cors
pnpm add @raptor-js/cors

Configuration

Like other first-party packages, an optional configuration object is available, allowing you to customise your CORS setup.

import { Config } from "@raptor-js/cors";
import { HttpMethod } from "@raptor-js/types";
 
const config = {
  /**
   * Allowed origin(s) for CORS requests.
   */
  origin: "http://localhost:8000",
 
  /**
   * Allowed HTTP methods for CORS requests.
   */
  methods: [
    HttpMethod.GET,
    HttpMethod.POST,
    HttpMethod.PUT,
    HttpMethod.DELETE,
    HttpMethod.OPTIONS,
  ],
 
  /**
   * Allowed request headers for CORS requests.
   */
  headers: ["Content-Type", "Authorization"],
 
  /**
   * How long (in seconds) the preflight response can be cached.
   */
  maxAge: "86400",
} satisfies Config;
 
export default config;

Usage

You can use this package in exactly the same way as other Raptor middleware:

import config from "./cors.config.ts";
 
app.use(cors(config));
© 2026 Raptor