• Documentation
  • /
  • Remix Firebase
  • /
  • Enable CORS

Enable CORS

Enabling CORS is required if you want to allow serving HTTP request to external clients.

For example, if you want to expose an API to some consumers: JS libraries, headless clients, and so on.

To enable CORS, you can simply call it in your handler. If it fails, it will throw an exception with the appropriate HTTP status code.

import withCors from '~/core/middleware/with-cors';

export const action: ActionFunction = async ({request}) => {
  // your logic

export default apiHandler;

Additionally, you need to respond to OPTIONS request appropriately.

export function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {

  if (req.method === `OPTIONS`) {
     // add the method you want to allow
     res.setHeader('Access-Control-Allow-Methods', 'GET');

     return res.end();

Stay informed with our latest resources for building a SaaS

Subscribe to our newsletter to receive updatesor