Skip to content
atarashi
Documentation menu

mw/cors

Cross-origin request handling driven by a CORS_ORIGIN allow-list, for Express, Fastify or Hono.

Provides: middleware:cors

Requires: http, config:env

Dependencies

  • cors@^2.8.5 (when has('http/express'))
  • @fastify/cors@^11.1.0 (when has('http/fastify'))

Development only:

  • @types/cors@^2.8.19 (when provides('language:typescript') && has('http/express'))

Environment

VariableRequiredDescription
CORS_ORIGINnoComma-separated list of allowed origins, or * for any

What it contributes to other files

FileSlotLine
src/config/env.ts|jsenv-schemaCORS_ORIGIN: z.string().default('*'),
src/app.ts|jsimportsimport { env } from './config/env.js';
src/app.ts|jsimportsimport cors from 'cors';
src/app.ts|jsmiddlewareapp.use(
src/app.ts|jsimportsimport fastifyCors from '@fastify/cors';
src/app.ts|jsmiddlewareawait app.register(fastifyCors, {
src/app.ts|jsimportsimport { cors } from 'hono/cors';
src/app.ts|jsmiddlewareapp.use(

Use it

atarashi new my-app --add mw/cors
atarashi add mw/cors

Version 1.0.0. Format reference: Authoring blueprints.

Part of the atarashi documentation, written and maintained by Gautam Suthar.