Skip to content

Commit

Permalink
Add jsdoc types to docs snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed Jul 12, 2021
1 parent f52955e commit fa0fe5d
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 1 deletion.
32 changes: 32 additions & 0 deletions docs/api-reference/next.config.js/headers.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Headers allow you to set custom HTTP headers for an incoming request path.
To set custom HTTP headers you can use the `headers` key in `next.config.js`:

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async headers() {
return [
Expand Down Expand Up @@ -62,6 +66,9 @@ Headers are checked before the filesystem which includes pages and `/public` fil
If two headers match the same path and set the same header key, the last header key will override the first. Using the below headers, the path `/hello` will result in the header `x-hello` being `world` due to the last header value set being `world`.

```js
/**
* @type {import('next').NextConfig}
*/
module.exports = {
async headers() {
return [
Expand Down Expand Up @@ -93,6 +100,9 @@ module.exports = {
Path matches are allowed, for example `/blog/:slug` will match `/blog/hello-world` (no nested paths):

```js
/**
* @type {import('next').NextConfig}
*/
module.exports = {
async headers() {
return [
Expand All @@ -119,6 +129,9 @@ module.exports = {
To match a wildcard path you can use `*` after a parameter, for example `/blog/:slug*` will match `/blog/a/b/c/d/hello-world`:

```js
/**
* @type {import('next').NextConfig}
*/
module.exports = {
async headers() {
return [
Expand All @@ -145,6 +158,9 @@ module.exports = {
To match a regex path you can wrap the regex in parenthesis after a parameter, for example `/blog/:slug(\\d{1,})` will match `/blog/123` but not `/blog/abc`:

```js
/**
* @type {import('next').NextConfig}
*/
module.exports = {
async headers() {
return [
Expand All @@ -165,6 +181,10 @@ module.exports = {
The following characters `(`, `)`, `{`, `}`, `:`, `*`, `+`, `?` are used for regex path matching, so when used in the `source` as non-special values they must be escaped by adding `\\` before them:

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async redirects() {
return [
Expand All @@ -190,6 +210,10 @@ To only apply a header when either header, cookie, or query values also match th
- `value`: `String` or `undefined` - the value to check for, if undefined any value will match. A regex like string can be used to capture a specific part of the value, e.g. if the value `first-(?<paramName>.*)` is used for `first-second` then `second` will be usable in the destination with `:paramName`.

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async headers() {
return [
Expand Down Expand Up @@ -281,6 +305,10 @@ module.exports = {
When leveraging [`basePath` support](/docs/api-reference/next.config.js/basepath.md) with headers each `source` is automatically prefixed with the `basePath` unless you add `basePath: false` to the header:

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
basePath: '/docs',

Expand Down Expand Up @@ -315,6 +343,10 @@ module.exports = {
When leveraging [`i18n` support](/docs/advanced-features/i18n-routing.md) with headers each `source` is automatically prefixed to handle the configured `locales` unless you add `locale: false` to the header. If `locale: false` is used you must prefix the `source` with a locale for it to be matched correctly.

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
i18n: {
locales: ['en', 'fr', 'de'],
Expand Down
10 changes: 9 additions & 1 deletion docs/api-reference/next.config.js/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ For custom advanced behavior of Next.js, you can create a `next.config.js` in th
Take a look at the following `next.config.js` example:

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
/* config options here */
}
Expand All @@ -20,9 +24,13 @@ You can also use a function:

```js
module.exports = (phase, { defaultConfig }) => {
return {
/**
* @type {import('next').NextConfig}
*/
const config = {
/* config options here */
}
return config
}
```

Expand Down
31 changes: 31 additions & 0 deletions docs/api-reference/next.config.js/redirects.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Redirects are only available on the Node.js environment and do not affect client
To use Redirects you can use the `redirects` key in `next.config.js`:

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async redirects() {
return [
Expand Down Expand Up @@ -57,6 +61,10 @@ Redirects are checked before the filesystem which includes pages and `/public` f
Path matches are allowed, for example `/old-blog/:slug` will match `/old-blog/hello-world` (no nested paths):

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async redirects() {
return [
Expand All @@ -75,6 +83,10 @@ module.exports = {
To match a wildcard path you can use `*` after a parameter, for example `/blog/:slug*` will match `/blog/a/b/c/d/hello-world`:

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async redirects() {
return [
Expand All @@ -93,6 +105,10 @@ module.exports = {
To match a regex path you can wrap the regex in parentheses after a parameter, for example `/post/:slug(\\d{1,})` will match `/post/123` but not `/post/abc`:

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async redirects() {
return [
Expand All @@ -109,6 +125,10 @@ module.exports = {
The following characters `(`, `)`, `{`, `}`, `:`, `*`, `+`, `?` are used for regex path matching, so when used in the `source` as non-special values they must be escaped by adding `\\` before them:

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async redirects() {
return [
Expand All @@ -134,6 +154,9 @@ To only match a redirect when header, cookie, or query values also match the `ha
- `value`: `String` or `undefined` - the value to check for, if undefined any value will match. A regex like string can be used to capture a specific part of the value, e.g. if the value `first-(?<paramName>.*)` is used for `first-second` then `second` will be usable in the destination with `:paramName`.

```js
/**
* @type {import('next').NextConfig}
*/
module.exports = {
async redirects() {
return [
Expand Down Expand Up @@ -208,6 +231,10 @@ module.exports = {
When leveraging [`basePath` support](/docs/api-reference/next.config.js/basepath.md) with redirects each `source` and `destination` is automatically prefixed with the `basePath` unless you add `basePath: false` to the redirect:

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
basePath: '/docs',

Expand Down Expand Up @@ -235,6 +262,10 @@ module.exports = {
When leveraging [`i18n` support](/docs/advanced-features/i18n-routing.md) with redirects each `source` and `destination` is automatically prefixed to handle the configured `locales` unless you add `locale: false` to the redirect. If `locale: false` is used you must prefix the `source` and `destination` with a locale for it to be matched correctly.

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
i18n: {
locales: ['en', 'fr', 'de'],
Expand Down
56 changes: 56 additions & 0 deletions docs/api-reference/next.config.js/rewrites.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Rewrites act as a URL proxy and mask the destination path, making it appear the
To use rewrites you can use the `rewrites` key in `next.config.js`:

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async rewrites() {
return [
Expand All @@ -53,6 +57,10 @@ Rewrites are applied to client-side routing, a `<Link href="/about">` will have
Rewrites are applied after checking the filesystem (pages and `/public` files) and before dynamic routes by default. This behavior can be changed by instead returning an object instead of an array from the `rewrites` function since `v10.1` of Next.js:

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async rewrites() {
return {
Expand Down Expand Up @@ -92,6 +100,10 @@ module.exports = {
When using parameters in a rewrite the parameters will be passed in the query by default when none of the parameters are used in the `destination`.

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async rewrites() {
return [
Expand All @@ -107,6 +119,10 @@ module.exports = {
If a parameter is used in the destination none of the parameters will be automatically passed in the query.

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async rewrites() {
return [
Expand All @@ -122,6 +138,10 @@ module.exports = {
You can still pass the parameters manually in the query if one is already used in the destination by specifying the query in the `destination`.

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async rewrites() {
return [
Expand All @@ -142,6 +162,10 @@ module.exports = {
Path matches are allowed, for example `/blog/:slug` will match `/blog/hello-world` (no nested paths):

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async rewrites() {
return [
Expand All @@ -159,6 +183,10 @@ module.exports = {
To match a wildcard path you can use `*` after a parameter, for example `/blog/:slug*` will match `/blog/a/b/c/d/hello-world`:

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async rewrites() {
return [
Expand All @@ -176,6 +204,10 @@ module.exports = {
To match a regex path you can wrap the regex in parenthesis after a parameter, for example `/blog/:slug(\\d{1,})` will match `/blog/123` but not `/blog/abc`:

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async rewrites() {
return [
Expand All @@ -191,6 +223,10 @@ module.exports = {
The following characters `(`, `)`, `{`, `}`, `:`, `*`, `+`, `?` are used for regex path matching, so when used in the `source` as non-special values they must be escaped by adding `\\` before them:

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async redirects() {
return [
Expand All @@ -216,6 +252,10 @@ To only match a rewrite when header, cookie, or query values also match the `has
- `value`: `String` or `undefined` - the value to check for, if undefined any value will match. A regex like string can be used to capture a specific part of the value, e.g. if the value `first-(?<paramName>.*)` is used for `first-second` then `second` will be usable in the destination with `:paramName`.

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async rewrites() {
return [
Expand Down Expand Up @@ -294,6 +334,10 @@ module.exports = {
Rewrites allow you to rewrite to an external url. This is especially useful for incrementally adopting Next.js.

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async rewrites() {
return [
Expand All @@ -313,6 +357,10 @@ You can also have Next.js fall back to proxying to an existing website after che
This way you don't have to change the rewrites configuration when migrating more pages to Next.js

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
async rewrites() {
return {
Expand All @@ -334,6 +382,10 @@ See additional information on incremental adoption [in the docs here](/docs/migr
When leveraging [`basePath` support](/docs/api-reference/next.config.js/basepath.md) with rewrites each `source` and `destination` is automatically prefixed with the `basePath` unless you add `basePath: false` to the rewrite:

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
basePath: '/docs',

Expand All @@ -360,6 +412,10 @@ module.exports = {
When leveraging [`i18n` support](/docs/advanced-features/i18n-routing.md) with rewrites each `source` and `destination` is automatically prefixed to handle the configured `locales` unless you add `locale: false` to the rewrite. If `locale: false` is used you must prefix the `source` and `destination` with a locale for it to be matched correctly.

```js
/**
* @type {import('next').NextConfig}
*/

module.exports = {
i18n: {
locales: ['en', 'fr', 'de'],
Expand Down

0 comments on commit fa0fe5d

Please sign in to comment.