CORS — Middleware · Hono

Let a browser app on another origin call the cats API: answer the preflight, name the origins, methods and headers that are allowed, expose a custom header, and keep the rest of the API untouched.

What you will learn

Read the theory for CORS

All Middleware lessons

All Hono courses

loading types…

What you'll learn

  • Read what a browser sends before a cross-origin request, the OPTIONS preflight, and what cors() answers
  • Configure origin, allowMethods, allowHeaders, exposeHeaders, maxAge and credentials, and see each become a header
  • Scope CORS to the routes that need it and understand that an origin not on the list simply gets no permission