Skip to content

Commit 027ee85

Browse files
committed
docs: use cleaner imports in examples and add read more links to config (#4200)
1 parent 4fe1fa6 commit 027ee85

24 files changed

Lines changed: 243 additions & 221 deletions

docs/1.docs/2.quick-start.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ export default defineConfig({
6161
Create a `nitro.config.ts` to configure the server directory:
6262

6363
```ts [nitro.config.ts]
64-
import { defineNitroConfig } from "nitro/config";
64+
import { defineConfig } from "nitro";
6565

66-
export default defineNitroConfig({
66+
export default defineConfig({
6767
serverDir: "./server",
6868
});
6969
```
@@ -83,9 +83,9 @@ export default defineHandler(() => {
8383
});
8484
```
8585
```ts [nitro.config.ts]
86-
import { defineNitroConfig } from "nitro/config";
86+
import { defineConfig } from "nitro";
8787

88-
export default defineNitroConfig({
88+
export default defineConfig({
8989
serverDir: "./server",
9090
});
9191
```

docs/1.docs/4.renderer.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ The renderer is a special handler in Nitro that catches all routes that don't ma
1515
The renderer is configured using the `renderer` option in your Nitro config:
1616

1717
```ts [nitro.config.ts]
18-
import { defineNitroConfig } from "nitro/config";
18+
import { defineConfig } from "nitro";
1919

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

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

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

113113
```ts [nitro.config.ts]
114-
import { defineNitroConfig } from "nitro/config";
114+
import { defineConfig } from "nitro";
115115

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

250250
```ts [nitro.config.ts]
251-
import { defineNitroConfig } from "nitro/config";
251+
import { defineConfig } from "nitro";
252252

253-
export default defineNitroConfig({
253+
export default defineConfig({
254254
renderer: {
255255
handler: './renderer.ts'
256256
}

docs/1.docs/5.routing.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ routes/
213213
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.
214214

215215
```ts [nitro.config.ts]
216-
import { defineNitroConfig } from "nitro/config";
216+
import { defineConfig } from "nitro";
217217

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

235235
```ts [nitro.config.ts]
236-
import { defineNitroConfig } from "nitro/config";
236+
import { defineConfig } from "nitro";
237237

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

267267
```ts [nitro.config.ts]
268-
import { defineNitroConfig } from "nitro/config";
268+
import { defineConfig } from "nitro";
269269

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

404404
```ts [nitro.config.ts]
405-
import { defineNitroConfig } from "nitro/config";
405+
import { defineConfig } from "nitro";
406406

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

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

440-
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.
440+
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.
441441

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

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

474474
```ts [nitro.config.ts]
475-
import { defineNitroConfig } from "nitro/config";
475+
import { defineConfig } from "nitro";
476476

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

491491
```ts [nitro.config.ts]
492-
import { defineNitroConfig } from "nitro/config";
492+
import { defineConfig } from "nitro";
493493

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

508508
```ts [nitro.config.ts]
509-
import { defineNitroConfig } from "nitro/config";
509+
import { defineConfig } from "nitro";
510510

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

525525
```ts [nitro.config.ts]
526-
import { defineNitroConfig } from "nitro/config";
526+
import { defineConfig } from "nitro";
527527

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

544544
```ts [nitro.config.ts]
545-
import { defineNitroConfig } from "nitro/config";
545+
import { defineConfig } from "nitro";
546546

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

570570
```ts [nitro.config.ts]
571-
import { defineNitroConfig } from "nitro/config";
571+
import { defineConfig } from "nitro";
572572

573-
export default defineNitroConfig({
573+
export default defineConfig({
574574
routeRules: {
575575
'/admin/**': {
576576
basicAuth: {
@@ -590,9 +590,9 @@ export default defineNitroConfig({
590590
Control caching behavior with `cache`, `swr`, or `static` options:
591591

592592
```ts [nitro.config.ts]
593-
import { defineNitroConfig } from "nitro/config";
593+
import { defineConfig } from "nitro";
594594

595-
export default defineNitroConfig({
595+
export default defineConfig({
596596
routeRules: {
597597
// Enable stale-while-revalidate caching
598598
'/blog/**': { swr: true },
@@ -621,9 +621,9 @@ export default defineNitroConfig({
621621
Mark routes for prerendering at build time:
622622

623623
```ts [nitro.config.ts]
624-
import { defineNitroConfig } from "nitro/config";
624+
import { defineConfig } from "nitro";
625625

626-
export default defineNitroConfig({
626+
export default defineConfig({
627627
routeRules: {
628628
'/about': { prerender: true },
629629
'/dynamic/**': { prerender: false },
@@ -636,9 +636,9 @@ export default defineNitroConfig({
636636
Configure Incremental Static Regeneration for Vercel deployments:
637637

638638
```ts [nitro.config.ts]
639-
import { defineNitroConfig } from "nitro/config";
639+
import { defineConfig } from "nitro";
640640

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

675675
```ts [nitro.config.ts]
676-
import { defineNitroConfig } from "nitro/config";
676+
import { defineConfig } from "nitro";
677677

678-
export default defineNitroConfig({
678+
export default defineConfig({
679679
runtimeConfig: {
680680
nitro: {
681681
routeRules: {

docs/1.docs/50.assets.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ You can configure additional public asset directories using the `publicAssets` c
6565
- `ignore` -- Pass `false` to disable ignore patterns, or an array of glob patterns to override the global `ignore` option.
6666

6767
```js [nitro.config.ts]
68-
import { defineNitroConfig } from "nitro/config";
68+
import { defineConfig } from "nitro";
6969

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

8989
```js [nitro.config.ts]
90-
import { defineNitroConfig } from "nitro/config";
90+
import { defineConfig } from "nitro";
9191

92-
export default defineNitroConfig({
92+
export default defineConfig({
9393
compressPublicAssets: true,
9494
});
9595
```
9696

9797
Or pick specific encodings:
9898

9999
```js [nitro.config.ts]
100-
import { defineNitroConfig } from "nitro/config";
100+
import { defineConfig } from "nitro";
101101

102-
export default defineNitroConfig({
102+
export default defineConfig({
103103
compressPublicAssets: {
104104
gzip: true,
105105
brotli: true,
@@ -144,9 +144,9 @@ Each entry in `serverAssets` supports the following properties:
144144
- `ignore` -- Array of glob patterns to exclude files.
145145

146146
```js [nitro.config.ts]
147-
import { defineNitroConfig } from "nitro/config";
147+
import { defineConfig } from "nitro";
148148

149-
export default defineNitroConfig({
149+
export default defineConfig({
150150
serverAssets: [
151151
{
152152
baseName: "templates",

0 commit comments

Comments
 (0)