/Knowledge/sources/honojs__hono/llms-full/cors-middleware-environment-dependent-cors-configuration--286b4e18c99b.md
CORS Middleware: Environment-dependent CORS configuration - hono-docs
CORS Middleware: Environment dependent CORS configuration Source evidence: /Sources/honojs hono/provenance.md Canonical citation: https://hono.dev/llms full....
CORS Middleware: Environment-dependent CORS configuration
Source evidence: /Sources/honojs__hono/provenance.md Canonical citation: https://hono.dev/llms-full.txt#environment-dependent-cors-configuration
Summary
If you want to adjust CORS configuration according to the execution environment, such as development or production, injecting values from environment variables is convenient as it eliminates the need for the application to be aware of it...
Content
If you want to adjust CORS configuration according to the execution environment, such as development or production, injecting values from environment variables is convenient as it eliminates the need for the application to be aware of its own execution environment. See the example below for clarification.
app.use('*', async (c, next) => {
const corsMiddlewareHandler = cors({
origin: c.env.CORS_ORIGIN,
})
return corsMiddlewareHandler(c, next)
})
Metadata
{
"chunk_index": 0,
"citation": "https://hono.dev/llms-full.txt#environment-dependent-cors-configuration",
"coverage_role": "overview",
"qualified_title": "Hono / llms-full / CORS Middleware > Environment-dependent CORS configuration",
"retrieved_at": "2026-07-02T05:51:01Z",
"section_index": 195,
"source_id": "/honojs/hono",
"source_type": "llms_full",
"target_label": "llms-full",
"title": "CORS Middleware: Environment-dependent CORS configuration",
"upstream_url": "https://hono.dev/llms-full.txt",
"version": "2026"
}