Skip to content

Enabling CORS in Yelix

Cross-Origin Resource Sharing (CORS) is a security feature implemented by web browsers to restrict web pages from making requests to a different domain than the one that served the web page. In Yelix, you can easily enable CORS using middleware.

import { YelixHono } from '@yelix/hono';
import { cors } from 'hono/cors';
const app = new YelixHono();
app.use(cors()); // Enable CORS for all routes with default settings
app.get('/', (c) => {
return c.text('CORS is enabled!');
});
Deno.serve(app.fetch);
import { YelixHono } from '@yelix/hono';
import { cors } from 'hono/cors';
const app = new YelixHono();
app.use(cors(
// Optional: Customize CORS options here
));
app.get('/', (c) => {
return c.text('CORS is enabled!');
});
Deno.serve(app.fetch);