Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/1.docs/2.quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export default defineConfig({
Create a `nitro.config.ts` to configure the server directory:

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
serverDir: "./server",
});
```
Expand All @@ -83,9 +83,9 @@ export default defineHandler(() => {
});
```
```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
serverDir: "./server",
});
```
Expand Down
16 changes: 8 additions & 8 deletions docs/1.docs/4.renderer.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ The renderer is a special handler in Nitro that catches all routes that don't ma
The renderer is configured using the `renderer` option in your Nitro config:

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
renderer: {
template: './index.html', // Path to HTML template file
handler: './renderer.ts', // Path to custom renderer handler
Expand Down Expand Up @@ -80,9 +80,9 @@ You can specify a custom HTML template file using the `renderer.template` option

::code-group
```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
renderer: {
template: './app.html'
}
Expand Down Expand Up @@ -111,9 +111,9 @@ By default, Nitro auto-detects whether your HTML template contains [rendu](#hype
You can override this behavior with the `static` option:

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
renderer: {
template: './index.html',
static: true // Force static serving, skip template processing
Expand Down Expand Up @@ -248,9 +248,9 @@ export default function renderer({ req }: { req: Request }) {
Then, specify the renderer entry in the Nitro config:

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
renderer: {
handler: './renderer.ts'
}
Expand Down
60 changes: 30 additions & 30 deletions docs/1.docs/5.routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ routes/
You can use the `ignore` config option to exclude files from route scanning. It accepts an array of glob patterns relative to the server directory.

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
ignore: [
"routes/api/**/_*", // Ignore files starting with _ in api/
"middleware/_*.ts", // Ignore middleware starting with _
Expand All @@ -233,9 +233,9 @@ In addition to filesystem routing, you can register route handlers programmatica
The `routes` option allows you to map route patterns to handlers:

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
routes: {
"/api/hello": "./server/routes/api/hello.ts",
"/api/custom": {
Expand Down Expand Up @@ -265,9 +265,9 @@ Each route entry can be a simple string (handler path) or an object with the fol
The `handlers` array is useful for registering middleware with control over route matching:

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
handlers: [
{
route: "/api/**",
Expand Down Expand Up @@ -402,9 +402,9 @@ export default defineHandler((event) => {
You can register middleware for specific route patterns using the [`handlers`](#handlers-config) config with the `middleware` option and a specific `route`:

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
handlers: [
{
route: "/api/**",
Expand Down Expand Up @@ -437,7 +437,7 @@ Nitro allows you to add logic at the top-level for each route of your configurat

It is a map from route pattern (following [rou3](https://github.com/h3js/rou3)) to route options.

When `cache` option is set, handlers matching pattern will be automatically wrapped with `defineCachedEventHandler`. See the [cache guide](/docs/cache) to learn more about this function.
When `cache` option is set, handlers matching pattern will be automatically wrapped with `defineCachedHandler`. See the [cache guide](/docs/cache) to learn more about this function.

::note
`swr: true|number` is shortcut for `cache: { swr: true, maxAge: number }`
Expand All @@ -448,7 +448,7 @@ You can set route rules in the `nitro.routeRules` options.
```ts [nitro.config.ts]
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
routeRules: {
'/blog/**': { swr: true },
'/blog2/**': { swr: 600 },
Expand All @@ -472,9 +472,9 @@ Route rules are matched from least specific to most specific. When multiple rule
You can use `false` to disable a rule that was set by a more general pattern:

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
routeRules: {
'/api/cached/**': { swr: true },
'/api/cached/no-cache': { cache: false, swr: false },
Expand All @@ -489,9 +489,9 @@ export default defineNitroConfig({
Set custom response headers for matching routes:

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
routeRules: {
'/api/**': { headers: { 'cache-control': 's-maxage=60' } },
'**': { headers: { 'x-powered-by': 'Nitro' } },
Expand All @@ -506,9 +506,9 @@ Enable CORS headers with the `cors: true` shortcut. This sets `access-control-al
You can override individual CORS headers using `headers`:

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
routeRules: {
'/api/v1/**': {
cors: true,
Expand All @@ -523,9 +523,9 @@ export default defineNitroConfig({
Redirect matching routes to another URL. Use a string for a simple redirect (defaults to `307` status), or an object for more control:

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
routeRules: {
// Simple redirect (307 status)
'/old-page': { redirect: '/new-page' },
Expand All @@ -542,9 +542,9 @@ export default defineNitroConfig({
Proxy requests to another URL. Supports both internal and external targets:

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
routeRules: {
// Proxy to exact URL
'/api/proxy/example': { proxy: 'https://example.com' },
Expand All @@ -568,9 +568,9 @@ export default defineNitroConfig({
Protect routes with HTTP Basic Authentication:

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
routeRules: {
'/admin/**': {
basicAuth: {
Expand All @@ -590,9 +590,9 @@ export default defineNitroConfig({
Control caching behavior with `cache`, `swr`, or `static` options:

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
routeRules: {
// Enable stale-while-revalidate caching
'/blog/**': { swr: true },
Expand Down Expand Up @@ -621,9 +621,9 @@ export default defineNitroConfig({
Mark routes for prerendering at build time:

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
routeRules: {
'/about': { prerender: true },
'/dynamic/**': { prerender: false },
Expand All @@ -636,9 +636,9 @@ export default defineNitroConfig({
Configure Incremental Static Regeneration for Vercel deployments:

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
routeRules: {
'/isr/**': { isr: true },
'/isr-ttl/**': { isr: 60 },
Expand Down Expand Up @@ -673,9 +673,9 @@ export default defineNitroConfig({
Route rules can be provided through `runtimeConfig`, allowing overrides via environment variables without rebuilding:

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
runtimeConfig: {
nitro: {
routeRules: {
Expand Down
16 changes: 8 additions & 8 deletions docs/1.docs/50.assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ You can configure additional public asset directories using the `publicAssets` c
- `ignore` -- Pass `false` to disable ignore patterns, or an array of glob patterns to override the global `ignore` option.

```js [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
publicAssets: [
{
baseURL: "build",
Expand All @@ -87,19 +87,19 @@ Nitro can generate pre-compressed versions of your public assets during the buil
Set `compressPublicAssets: true` to enable all encodings:

```js [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
compressPublicAssets: true,
});
```

Or pick specific encodings:

```js [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
compressPublicAssets: {
gzip: true,
brotli: true,
Expand Down Expand Up @@ -144,9 +144,9 @@ Each entry in `serverAssets` supports the following properties:
- `ignore` -- Array of glob patterns to exclude files.

```js [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";
import { defineConfig } from "nitro";

export default defineNitroConfig({
export default defineConfig({
serverAssets: [
{
baseName: "templates",
Expand Down
Loading
Loading