Skip to content

Route Rules ‚Äč

Vinxi exposes the route rules feature of Nitro. This allows you to configure the server to handle certain routes in a specific way. For example, you can configure a route to proxy requests to another server, or redirect a route to another route. This is incredibly powerful to overlay server behaviour on top of your normal applications.

ts
import { createApp } from "vinxi";

export default createApp({
  server: {
    routeRules: {
      "/_build/assets/**": { headers: { "cache-control": "s-maxage=0" } },
      "/api/v1/**": {
        cors: true,
        headers: { "access-control-allow-methods": "GET" },
      },
      "/old-page": { redirect: "/new-page" },
      "/proxy/example": { proxy: "https://example.com" },
      "/proxy/**": { proxy: "/api/**" },
    },
  },
  routers: [
    // ...
  ],
});