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 via the CLI or, if you are using Deno, import it directly from JSR.
deno add jsr:@raptor/corsbunx jsr add @raptor/corsnpx jsr add @raptor/corsyarn dlx jsr add @raptor/corspnpm dlx jsr add @raptor/corsConfiguration
Like other first-party packages, an optional configuration object is available, allowing you to customise your CORS setup.
import { Config } from "@raptor/cors";
import { HttpMethod } from "@raptor/kernel";
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));