You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: contributing.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
Our Commitment to Open Source can be found [here](https://vercel.com/oss).
4
4
5
5
1.[Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device.
6
-
2. Create a new branch `git checkout -b MY_BRANCH_NAME`
6
+
2. Create a new branch:`git checkout -b MY_BRANCH_NAME`
7
7
3. Install yarn: `npm install -g yarn`
8
8
4. Install the dependencies: `yarn`
9
9
5. Run `yarn dev` to build and watch for code changes
Copy file name to clipboardExpand all lines: docs/advanced-features/custom-server.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ description: Start a Next.js app programmatically using a custom server.
15
15
</ul>
16
16
</details>
17
17
18
-
Typically you start your next server with `next start`. It's possible, however, to start a server 100% programmatically in order to use custom route patterns.
18
+
By default, Next.js includes its own server with `next start`. If you have an existing backend, you can still use it with Next.js (this is not a custom server). A custom Next.js server allows you to start a server 100% programmatically in order to use custom server patterns. Most of the time, you will not need this – but it's available for complete customization.
19
19
20
20
> A custom server **can not** be deployed on [Vercel](https://vercel.com/solutions/nextjs), the platform Next.js was made for.
Copy file name to clipboardExpand all lines: docs/api-reference/next.config.js/headers.md
+94Lines changed: 94 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -149,6 +149,100 @@ module.exports = {
149
149
}
150
150
```
151
151
152
+
## Header, Cookie, and Query Matching
153
+
154
+
To only apply a header when either header, cookie, or query values also match the `has` field can be used. Both the `source` and all `has` items must match for the header to be applied.
155
+
156
+
`has` items have the following fields:
157
+
158
+
-`type`: `String` - must be either `header`, `cookie`, `host`, or `query`.
159
+
-`key`: `String` - the key from the selected type to match against.
160
+
-`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`.
161
+
162
+
```js
163
+
module.exports= {
164
+
asyncheaders() {
165
+
return [
166
+
// if the header `x-add-header` is present,
167
+
// the `x-another-header` header will be applied
168
+
{
169
+
source:'/:path*',
170
+
has: [
171
+
{
172
+
type:'header',
173
+
key:'x-add-header',
174
+
},
175
+
],
176
+
headers: [
177
+
{
178
+
key:'x-another-header',
179
+
value:'hello',
180
+
},
181
+
],
182
+
},
183
+
// if the source, query, and cookie are matched,
184
+
// the `x-authorized` header will be applied
185
+
{
186
+
source:'/specific/:path*',
187
+
has: [
188
+
{
189
+
type:'query',
190
+
key:'page',
191
+
value:'home',
192
+
},
193
+
{
194
+
type:'cookie',
195
+
key:'authorized',
196
+
value:'true',
197
+
},
198
+
],
199
+
headers: [
200
+
{
201
+
key:'x-authorized',
202
+
value:':authorized',
203
+
},
204
+
],
205
+
},
206
+
// if the header `x-authorized` is present and
207
+
// contains a matching value, the `x-another-header` will be applied
208
+
{
209
+
source:'/:path*',
210
+
has: [
211
+
{
212
+
type:'header',
213
+
key:'x-authorized',
214
+
value:'(?<authorized>yes|true)',
215
+
},
216
+
],
217
+
headers: [
218
+
{
219
+
key:'x-another-header',
220
+
value:':authorized',
221
+
},
222
+
],
223
+
},
224
+
// if the host is `example.com`,
225
+
// this header will be applied
226
+
{
227
+
source:'/:path*',
228
+
has: [
229
+
{
230
+
type:'host',
231
+
value:'example.com',
232
+
},
233
+
],
234
+
headers: [
235
+
{
236
+
key:'x-another-header',
237
+
value:':authorized',
238
+
},
239
+
],
240
+
},
241
+
]
242
+
},
243
+
}
244
+
```
245
+
152
246
### Headers with basePath support
153
247
154
248
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:
The commented lines are the place where you can put the configs allowed by `next.config.js`, which are defined [here](https://github.com/vercel/next.js/blob/canary/packages/next/next-server/server/config.ts#L12-L63).
47
+
The commented lines are the place where you can put the configs allowed by `next.config.js`, which are defined [here](https://github.com/vercel/next.js/blob/canary/packages/next/next-server/server/config-shared.ts#L33).
48
48
49
49
However, none of the configs are required, and it's not necessary to understand what each config does. Instead, search for the features you need to enable or modify in this section and they will show you what to do.
Copy file name to clipboardExpand all lines: docs/api-reference/next.config.js/redirects.md
+77Lines changed: 77 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,6 +93,83 @@ module.exports = {
93
93
}
94
94
```
95
95
96
+
## Header, Cookie, and Query Matching
97
+
98
+
To only match a redirect when header, cookie, or query values also match the `has` field can be used. Both the `source` and all `has` items must match for the redirect to be applied.
99
+
100
+
`has` items have the following fields:
101
+
102
+
-`type`: `String` - must be either `header`, `cookie`, `host`, or `query`.
103
+
-`key`: `String` - the key from the selected type to match against.
104
+
-`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`.
105
+
106
+
```js
107
+
module.exports= {
108
+
asyncredirects() {
109
+
return [
110
+
// if the header `x-redirect-me` is present,
111
+
// this redirect will be applied
112
+
{
113
+
source:'/:path*',
114
+
has: [
115
+
{
116
+
type:'header',
117
+
key:'x-redirect-me',
118
+
},
119
+
],
120
+
permanent:false,
121
+
destination:'/another-page',
122
+
},
123
+
// if the source, query, and cookie are matched,
124
+
// this redirect will be applied
125
+
{
126
+
source:'/specific/:path*',
127
+
has: [
128
+
{
129
+
type:'query',
130
+
key:'page',
131
+
value:'home',
132
+
},
133
+
{
134
+
type:'cookie',
135
+
key:'authorized',
136
+
value:'true',
137
+
},
138
+
],
139
+
permanent:false,
140
+
destination:'/:path*/:page',
141
+
},
142
+
// if the header `x-authorized` is present and
143
+
// contains a matching value, this redirect will be applied
144
+
{
145
+
source:'/:path*',
146
+
has: [
147
+
{
148
+
type:'header',
149
+
key:'x-authorized',
150
+
value:'(?<authorized>yes|true)',
151
+
},
152
+
],
153
+
permanent:false,
154
+
destination:'/home?authorized=:authorized',
155
+
},
156
+
// if the host is `example.com`,
157
+
// this redirect will be applied
158
+
{
159
+
source:'/:path*',
160
+
has: [
161
+
{
162
+
type:'host',
163
+
value:'example.com',
164
+
},
165
+
],
166
+
destination:'/another-page',
167
+
},
168
+
]
169
+
},
170
+
}
171
+
```
172
+
96
173
### Redirects with basePath support
97
174
98
175
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:
0 commit comments