UNPKG

remix-utils

Version:

This package contains simple utility functions to use with [React Router](https://reactrouter.com/).

27 lines 1.09 kB
import { CORS } from "../cors.js"; /** * Creates a middleware function that applies CORS headers to the response. * * You can customize the CORS options by passing an object with the following * properties: * - origin: The origin(s) allowed to access the resource. This can be a * string, boolean, or an array of strings or regular expressions. * - methods: The HTTP methods allowed for cross-origin requests. * - allowedHeaders: The headers allowed in the request. * - exposedHeaders: The headers exposed to the client. * - credentials: Whether to include credentials in the request. * - maxAge: The maximum age of the preflight request in seconds. * * @param options Optional configuration for CORS * @returns A middleware function that applies CORS headers */ export function unstable_createCorsMiddleware(options) { let cors = new CORS(options); return [ async function corsMiddleware({ request }, next) { let response = await next(); return await cors.exec(request, response); }, ]; } //# sourceMappingURL=cors.js.map