Router API
Inspired by the Bun.App API, the core primitive in Vinxi is the router, which is simply a brief specification defining how a group of URLs should be handled.
Vinxi supports many common router types:
- 'static' - for serving uncompiled, static assets
- 'http' - for creating traditional web servers
- 'spa' - for building and serving single page application assets
- 'client' - for building and serving of SSR application assets
- custom - for adapting Vinxi to your use case
Creating a new router is as simple as adding a specification object to the routers
array in the createApp
call:
ts
import { createApp } from 'vinxi';
export default createApp({
routers: [
// A static router serving files from the `public` directory
{
name: 'public',
type: 'static',
dir: './public',
base: '/',
},
// A http router for an api
{
name: 'api',
type: 'http',
handler: './app/api.ts',
base: '/api',
plugins: () => [
// Vite plugins applying to exclusively to `http` router
]
}
],
});