8000 docs: improve configuration page · nitrojs/nitro@554b358 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 554b358

Browse files
authored
docs: improve configuration page
1 parent 8049f5b commit 554b358

File tree

1 file changed

+99
-81
lines changed

1 file changed

+99
-81
lines changed

docs/content/3.config/index.md

Lines changed: 99 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,24 @@ aside: false
66

77
Customize your Nitro app with a configuration file.
88

9-
In order to customize nitro's behavior, we create a file named `nitro.config.ts`.
9+
In order to customize Nitro's behavior, we create a file named `nitro.config.ts`.
1010

11-
```js
12-
// nitro.config.ts
11+
::code-group
12+
```ts [nitro.config.ts]
1313
import { defineNitroConfig } from "nitropack";
1414

15-
export default defineNitroConfig({});
15+
export default defineNitroConfig({
16+
// options
17+
});
1618
```
19+
```ts [nuxt.config.ts]
20+
export default defineNuxtConfig({
21+
nitro: {
22+
// options
23+
}
24+
})
25+
```
26+
::
1727

1828
## General
1929

@@ -27,19 +37,19 @@ The preset will automatically be detected when the `preset` option is not set an
2737

2838
### `logLevel`
2939

30-
- Default: `3` (`1` when the testing environment is detected)
40+
- Default: `3`{lang=ts} (`1`{lang=ts} when the testing environment is detected)
3141

3242
Log verbosity level. See [unjs/consola#level](https://github.com/unjs/consola/#level) for more information.
3343

3444
### `runtimeConfig`
3545

36-
- Default: `{ nitro: { ... }, ...yourOptions }`
46+
- Default: `{ nitro: { ... }, ...yourOptions }`{lang=ts}
3747

3848
Server runtime configuration.
3949

4050
**Note:**: `nitro` namespace is reserved.
4151

42-
<!-- Features -->
52+
## Features
4353

4454
### `experimental`
4555

@@ -51,11 +61,11 @@ Enable experimental features. Currently, none are available!
5161

5262
- Default: `{}`
5363

54-
Storage configuration.
64+
Storage configuration, read more in the [Storage Layer](/guide/introduction/storage) section.
5565

5666
### `timing`
5767

58-
- Default: `false`
68+
- Default: `false`{lang=ts}
5969

6070
Enable timing information:
6171

@@ -68,17 +78,18 @@ Path to main render (file should export an event handler as default)
6878

6979
### `serveStatic`
7080

71-
- Default: `false`
81+
- Type: `boolean` | `'node'`{lang=ts} | `'deno'`{lang=ts}
82+
- Default: depends of the deployment preset used.
7283

7384
Serve `public/` assets in production.
7485

75-
**Note:** It is highly recommended that your edge CDN (nginx, apache, cloud) serves the `public/` directory instead.
86+
**Note:** It is highly recommended that your edge CDN (nginx, apache, cloud) serves the `.output/public/` directory instead to enable compression and higher lever caching.
7687

7788
### `noPublicDir`
7889

79-
- Default: `false`
90+
- Default: `false`{lang=ts}
8091

81-
If enabled, disabled `.output/public` directory creation. Skipping to copy `public/` dir and also disables prerenderer.
92+
If enabled, disabled `.output/public` directory creation. Skipping to copy `public/` dir and also disables pre-renderering.
8293

8394
### `publicAssets`
8495

@@ -88,67 +99,70 @@ If a `public/` directory is detected, it will be added by default, but you can a
8899

89100
### `compressPublicAssets`
90101

91-
- Default: `{ gzip: false, brotli: false }`
102+
- Default: `{ gzip: false, brotli: false }`{lang=ts}
92103

93104
If enabled, Nitro will generate a pre-compressed (gzip and/or brotli) version of supported types of public assets and prerendered routes
94105
larger than 1024 bytes into the public directory. The best compression level is used. Using this option you can support zero overhead asset compression without using a CDN.
95106

96-
The compressible MIME types are:
97-
98-
- application/dash+xml
99-
- application/eot
100-
- application/font
101-
- application/font-sfnt
102-
- application/javascript
103-
- application/json
104-
- application/opentype
105-
- application/otf
106-
- application/pkcs7-mime
107-
- application/protobuf
108-
- application/rss+xml
109-
- application/truetype
110-
- application/ttf
111-
- application/vnd.apple.mpegurl
112-
- application/vnd.mapbox-vector-tile
113-
- application/vnd.ms-fontobject
114-
- application/xhtml+xml
115-
- application/xml
116-
- application/x-font-opentype
117-
- application/x-font-truetype
118-
- application/x-font-ttf
119-
- application/x-httpd-cgi
120-
- application/x-javascript
121-
- application/x-mpegurl
122-
- application/x-opentype
123-
- application/x-otf
124-
- application/x-perl
125-
- application/x-ttf
126-
- font/eot
127-
- font/opentype
128-
- font/otf
129-
- font/ttf
130-
- image/svg+xml
131-
- text/css
132-
- text/csv
133-
- text/html
134-
- text/javascript
135-
- text/js
136-
- text/plain
137-
- text/richtext
138-
- text/tab-separated-values
139-
- text/xml
140-
- text/x-component
141-
- text/x-java-source
142-
- text/x-script
143-
- vnd.apple.mpegurl
107+
::callout
108+
#summary
109+
List of compressible MIME types:
110+
#content
111+
- `application/dash+xml`
112+
- `application/eot`
113+
- `application/font`
114+
- `application/font-sfnt`
115+
- `application/javascript`
116+
- `application/json`
117+
- `application/opentype`
118+
- `application/otf`
119+
- `application/pkcs7-mime`
120+
- `application/protobuf`
121+
- `application/rss+xml`
122+
- `application/truetype`
123+
- `application/ttf`
124+
- `application/vnd.apple.mpegurl`
125+
- `application/vnd.mapbox-vector-tile`
126+
- `application/vnd.ms-fontobject`
127+
- `application/xhtml+xml`
128+
- `application/xml`
129+
- `application/x-font-opentype`
130+
- `application/x-font-truetype`
131+
- `application/x-font-ttf`
132+
- `application/x-httpd-cgi`
133+
- `application/x-javascript`
134+
- `application/x-mpegurl`
135+
- `application/x-opentype`
136+
- `application/x-otf`
137+
- `application/x-perl`
138+
- `application/x-ttf`
139+
- `font/eot`
140+
- `font/opentype`
141+
- `font/otf`
142+
- `font/ttf`
143+
- `image/svg+xml`
144+
- `text/css`
145+
- `text/csv`
146+
- `text/html`
147+
- `text/javascript`
148+
- `text/js`
149+
- `text/plain`
150+
- `text/richtext`
151+
- `text/tab-separated-values`
152+
- `text/xml`
153+
- `text/x-component`
154+
- `text/x-java-source`
155+
- `text/x-script`
156+
- `vnd.apple.mpegurl`
157+
::
144158

145159
### `serverAssets`
146160

147-
Assets can be accessed in server logic and bundled in production.
161+
Assets can be accessed in server logic and bundled in production. [Read more](/guide/introduction/assets#server-assets).
148162

149163
### `devServer`
150164

151-
- Default: `{ watch: [] }`
165+
- Default: `{ watch: [] }`{lang=ts}
152166

153167
Dev server options. You can use `watch` to make the dev server reload if any file changes in specified paths.
154168

@@ -172,11 +186,11 @@ An array of paths to nitro plugins. They will be executed by order on the first
172186

173187
A map from dynamic virtual import names to their contents or an (async) function that returns it.
174188

175-
<!-- Routing -->
189+
## Routing
176190

177191
### `baseURL`
178192

179-
Default: `/` (or `NITRO_APP_BASE_URL` environment variable if provided)
193+
Default: `/`{lang=ts} (or `NITRO_APP_BASE_URL` environment variable if provided)
180194

181195
Server's main base URL.
182196

@@ -239,23 +253,27 @@ export default <NitroErrorHandler> function (error, event) {
239253

240254
Route options. It is a map from route pattern (following [unjs/radix3](https://github.com/unjs/radix3#route-matcher)) to route options.
241255

242-
When `cache` option is set, handlers matching pattern will be automatically wrapped with `defineCachedEventHandler`. See [Cache API](/guide/introduction/cache) for all available cache options. (`swr: true|number` is shortcut for `cache: { swr: true, maxAge: number }`.)
256+
When `cache` option is set, handlers matching pattern will be automatically wrapped with `defineCachedEventHandler`.
257+
258+
See the [Cache API](/guide/introduction/cache) for all available cache options.
259+
260+
::alert
261+
`swr: true|number` is shortcut for `cache: { swr: true, maxAge: number }`
262+
::
243263

244264
**Example:**
245265

246266
```js
247-
{
248-
routeRules: {
249-
'/blog/**': { swr: true },
250-
'/blog/**': { swr: 600 },
251-
'/blog/**': { static: true },
252-
'/blog/**': { cache: { /* cache options*/ } },
253-
'/assets/**': { headers: { 'cache-control': 's-maxage=0' } },
254-
'/api/v1/**': { cors: true, headers: { 'access-control-allow-methods': 'GET' } },
255-
'/old-page': { redirect: '/new-page' },
256-
'/proxy/example': { proxy: 'https://example.com' },
257-
"/proxy/**": { proxy: '/api/**' },
258-
}
267+
routeRules: {
268+
'/blog/**': { swr: true },
269+
'/blog/**': { swr: 600 },
270+
'/blog/**': { static: true },
271+
'/blog/**': { cache: { /* cache options*/ } },
272+
'/assets/**': { headers: { 'cache-control': 's-maxage=0' } },
273+
'/api/v1/**': { cors: true, headers: { 'access-control-allow-methods': 'GET' } },
274+
'/old-page': { redirect: '/new-page' },
275+
'/proxy/example': { proxy: 'https://example.com' },
276+
"/proxy/**": { proxy: '/api/**' },
259277
}
260278
```
261279

@@ -269,7 +287,7 @@ Any route that starts with a prefix listed in `ignore` will be ignored.
269287

270288
If `crawlLinks` option is set to `true`, nitro starts with `/` by default (or all routes in `routes` array) and for HTML pages extracts `<a href="">` tags and prerender them as well.
271289

272-
<!-- Directories -->
290+
## Directories
273291

274292
### `rootDir`
275293

@@ -297,7 +315,7 @@ nitro's temporary working directory for generating build-related files.
297315

298316
Output directories for production bundle.
299317

300-
<!-- Advanced -->
318+
## Advanced
301319

302320
### `dev`
303321

0 commit comments

Comments
 (0)
0