Minor Changes
-
#720
91c7269Thanks @omeraplak! - fix: simplify CORS configuration and ensure custom routes are auth-protectedBreaking Changes
CORS Configuration
CORS configuration has been simplified. Instead of configuring CORS in
configureApp, use the newcorsfield:Before:
server: honoServer({ configureApp: (app) => { app.use( "*", cors({ origin: "https://your-domain.com", credentials: true, }) ); app.get("/api/health", (c) => c.json({ status: "ok" })); }, });
After (Simple global CORS):
server: honoServer({ cors: { origin: "https://your-domain.com", credentials: true, }, configureApp: (app) => { app.get("/api/health", (c) => c.json({ status: "ok" })); }, });
After (Route-specific CORS):
import { cors } from "hono/cors"; server: honoServer({ cors: false, // Disable default CORS for route-specific control configureApp: (app) => { // Different CORS for different routes app.use("/agents/*", cors({ origin: "https://agents.com" })); app.use("/api/public/*", cors({ origin: "*" })); app.get("/api/health", (c) => c.json({ status: "ok" })); }, });
Custom Routes Authentication
Custom routes added via
configureAppare now registered AFTER authentication middleware. This means:- Opt-in mode (default): Custom routes follow the same auth rules as built-in routes
- Opt-out mode (
defaultPrivate: true): Custom routes are automatically protected
Before: Custom routes bypassed authentication unless you manually added auth middleware.
After: Custom routes inherit authentication behavior automatically.
Example with opt-out mode:
server: honoServer({ auth: jwtAuth({ secret: process.env.JWT_SECRET, defaultPrivate: true, // Protect all routes by default publicRoutes: ["GET /api/health"], }), configureApp: (app) => { // This is now automatically protected app.get("/api/user/profile", (c) => { const user = c.get("authenticatedUser"); return c.json({ user }); // user is guaranteed to exist }); }, });
Why This Change?
- Security: Custom routes are no longer accidentally left unprotected
- Simplicity: CORS configuration is now a simple config field for common cases
- Flexibility: Advanced users can still use route-specific CORS with
cors: false - Consistency: Custom routes follow the same authentication rules as built-in routes
Patch Changes
- Updated dependencies [
efe4be6]:- @voltagent/core@1.1.33