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: articles/static-web-apps/deploy-nextjs-hybrid.md
+41-38Lines changed: 41 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -324,48 +324,51 @@ Your Next.js project can be configured to have custom handling of routes with re
324
324
Static Web Apps validates that your Next.js site is successfully deployed by adding a page to your site at build time. The page is named `public/.swa/health.html`, and Static Web Apps verifies the successful startup and deployment of your site by navigating to `/.swa/health.html` and verifying a successful response. Middleware and custom routing, which includes redirects and rewrites, can affect the access of the `/.swa/health.html` path, which can prevent Static Web Apps' deployment validation. To configure middleware and routing for a successful deployment to Static Web Apps, follow these steps:
325
325
326
326
1. Exclude routes starting with `.swa`in your `middleware.ts` (or `.js`) file in your middleware configuration.
327
-
```js
328
-
export const config = {
329
-
matcher: [
330
-
/*
331
-
* Match all request paths except for the ones starting with:
332
-
* - .swa (Azure Static Web Apps)
333
-
*/
334
-
'/((?!.swa).*)',
335
-
],
336
-
}
337
-
```
327
+
328
+
```js
329
+
export const config = {
330
+
matcher: [
331
+
/*
332
+
* Match all request paths except for the ones starting with:
333
+
* - .swa (Azure Static Web Apps)
334
+
*/
335
+
'/((?!.swa).*)',
336
+
],
337
+
}
338
+
```
338
339
339
340
1. Configure your redirects in`next.config.js` to exclude routes starting with `.swa`
340
-
```js
341
-
module.exports = {
342
-
async redirects() {
343
-
return [
344
-
{
345
-
source: '/((?!.swa).*)<YOUR MATCHING RULE>',
346
-
destination: '<YOUR REDIRECT RULE>',
347
-
permanent: false,
348
-
},
349
-
]
350
-
},
351
-
};
352
-
```
341
+
342
+
```js
343
+
module.exports = {
344
+
async redirects() {
345
+
return [
346
+
{
347
+
source: '/((?!.swa).*)<YOUR MATCHING RULE>',
348
+
destination: '<YOUR REDIRECT RULE>',
349
+
permanent: false,
350
+
},
351
+
]
352
+
},
353
+
};
354
+
```
353
355
354
356
1. Configure your rewrites in`next.config.js` to exclude routes starting with `.swa`
355
-
```js
356
-
module.exports = {
357
-
async rewrites() {
358
-
return {
359
-
beforeFiles: [
360
-
{
361
-
source: '/((?!.swa).*)<YOUR MATCHING RULE>',
362
-
destination: '<YOUR REWRITE RULE>',
363
-
}
364
-
]
365
-
}
366
-
},
367
-
};
368
-
```
357
+
358
+
```js
359
+
module.exports = {
360
+
async rewrites() {
361
+
return {
362
+
beforeFiles: [
363
+
{
364
+
source: '/((?!.swa).*)<YOUR MATCHING RULE>',
365
+
destination: '<YOUR REWRITE RULE>',
366
+
}
367
+
]
368
+
}
369
+
},
370
+
};
371
+
```
369
372
These code snippets exclude paths that start with `.swa` from being handled by your custom routing or middleware. These rules ensure that the paths resolve as expected during deployment validation.
0 commit comments