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/corsbun add @raptor-js/corsnpm install @raptor-js/corsyarn add @raptor-js/corspnpm add @raptor-js/corsConfiguration
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));